threads, sockets, pyopengl, pickle (and tkinter...)

Discussion in 'Python' started by Rod Stephenson, Jun 22, 2004.

  1. I am developing an engineering application for modelling multiphase
    flows in large pipe networks, and have just discovered the joy of
    pyopengl for 3D visualization. However the incantation I'm using -
    with glut on Windows - doesnt coexist well with other python gui's -
    glutMainLoop() appears not to work alongside tkinter.mainloop(). (I
    tried putting them in separate threads but no success there either)
    The issue has been raised in various discussions here in the past with
    no satisfacory resolution as far as I can see, though Togl has been
    suggested - but all I can find on the project page is c-source code,
    havent managed to get the demo Togl stuff in the pyopengl installation
    to work.

    Anyway, I've tried another avenue of attack - running the
    visualization portion in a separate application to the
    design/computation part, and communicating by sockets, this has a
    useful advantage that the two parts of the application can run on
    different machines if needed.

    So when I want to update the display, the design app packages up the
    drawing data into a display list (just a python list in fact
    with each entry an instruction to draw a particular element, colors
    etc), then pickles the thing up and send it through the socket.

    At the other end the display app reads from the socket - this runs in
    a separate thread, unpickles the data and puts it in a global variable
    which the gl drawing function can access. The two relevant routines
    and the stuff to fire everything off are appended. (doGlutMain() sets
    up all the gle stuff and sets glutDrawFunction() with DrawStuff)

    This *almost* works, except that things block until I generate some
    event in the OpenGL display window - even just giving it the focus
    after sending off some data. I'm not quite sure how to rectify this -
    any suggestions would be appreciated. Perhaps doing something with the
    glutIdleFunction()? And am I doing the right thing with the lock stuff?

    Finally could someone confirm that pickled data never contains a "."
    character apart at the end of the string (I use this as a delimiter in
    the socket communiction.) There was an old posting (from Guido
    himself) that seemed to imply this.

    Thanks

    rs


    # draw routine
    def DrawStuff():
    global lock
    glPushMatrix()
    someGLStuff()
    lock.acquire()
    if dList:
    for z in dList:
    draw(z)
    lock.release()
    glPopMatrix ()
    glutSwapBuffers ()


    # Server program
    def getData():
    global lock, dList
    HOST = ''
    PORT = 50007
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(1)
    conn, addr = s.accept()
    try:
    while 1:
    data=""
    while data[-1:] != ".":
    data += conn.recv(4096)
    try:
    z = cPickle.loads(data)
    lock.acquire()
    dList = z
    lock.release()
    glutPostRedisplay()
    print len(z)
    conn.send("OK")
    except:
    conn.send("rsnd")
    except:
    conn.close()


    thread.start_new_thread(getData, ())
    time.sleep(.1)
    doGlutMain(DrawStuff)







    --
    Bruce Rule 1.
    Rod Stephenson, Jun 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jupiter5F

    Threads and Sockets

    Jupiter5F, Nov 14, 2003, in forum: C++
    Replies:
    4
    Views:
    2,298
    Jupiter5F
    Nov 14, 2003
  2. Julia Goolia

    tkinter, sockets and threads together

    Julia Goolia, Sep 11, 2003, in forum: Python
    Replies:
    4
    Views:
    524
    Steve Holden
    Sep 12, 2003
  3. Gonçalo Rodrigues

    Help needed in problem with Threads and sockets.

    Gonçalo Rodrigues, Dec 29, 2003, in forum: Python
    Replies:
    0
    Views:
    265
    Gonçalo Rodrigues
    Dec 29, 2003
  4. a pickle's pickle

    , Aug 2, 2005, in forum: Python
    Replies:
    4
    Views:
    366
  5. Michele Simionato
    Replies:
    2
    Views:
    1,857
    Michele Simionato
    May 23, 2008
Loading...

Share This Page