threads, sockets, pyopengl, pickle (and tkinter...)
viking_kiwi at yahoo.poofters.com
Tue Jun 22 05:37:05 CEST 2004
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
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.
# draw routine
for z in dList:
# Server program
global lock, dList
HOST = ''
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn, addr = s.accept()
while data[-1:] != ".":
data += conn.recv(4096)
z = cPickle.loads(data)
dList = z
Bruce Rule 1.
More information about the Python-list