469,631 Members | 979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

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

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.


# draw routine
def DrawStuff():
global lock
if dList:
for z in dList:
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))
conn, addr = s.accept()
while 1:
while data[-1:] != ".":
data += conn.recv(4096)
z = cPickle.loads(data)
dList = z
print len(z)
thread.start_new_thread(getData, ())

Bruce Rule 1.
Jul 18 '05 #1
0 1642

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.