Threading issue
Threading issue
- Subject: Threading issue
- From: Bruce Sherwood <email@hidden>
- Date: Fri, 20 Jul 2012 13:04:29 -0600
I want to make a version of VPython (vpython.org) that is based on
Cocoa (the Mac version is currently based on Carbon).
The VPython API permits the following short user program, which
displays a 3D cube moving to the right, and you can rotate and zoom
the camera with the mouse:
from visual import box
b = box()
while True:
b.pos.x += 0.001
This works because a GUI environment is invoked by the visual module
in a secondary thread (written mainly in C++, connected to Python by
Boost). The OpenGL rendering of the box in its current position is
driven by a 30-millisecond timer. This works with any environment
other than Cocoa.
However, the Cocoa GUI environment and interact loop are required to
be in the primary thread, so the challenge is to have the visual
module set up the Cocoa environment, with the user's program running
in a secondary thread.
One of the things I've tried is to have the visual module read the
user's program, comment out the import statement, and start a
secondary thread in which I execute the (modified) user's code using
the Python exec statement. This has the problem that threads started
in Python modules apparently cannot execute import statements, so that
if there are additional import statements in the user's program (such
as importing math functions), the program halts. I've written code to
find all import statements in the user's program, execute them to add
their symbols to the global symbol table, and pass them as the
environment for the exec statement, but that's a pretty gross kludge.
Any suggestions?
Bruce Sherwood
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden