[Python-bugs-list] [ python-Bugs-539990 ] Framework.mainloop() - multiple threads

noreply@sourceforge.net noreply@sourceforge.net
Mon, 22 Apr 2002 07:03:25 -0700


Bugs item #539990, was opened at 2002-04-05 23:29
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=539990&group_id=5470

Category: Macintosh
Group: Platform-specific
Status: Open
Resolution: None
>Priority: 7
Submitted By: Pieter Claerhout (pclaerhout)
Assigned to: Jack Jansen (jackjansen)
Summary: Framework.mainloop() - multiple threads

Initial Comment:
I tried to use the threading module to start the XML 
RPC server in a different thread (xmlrpcServer itself 
also is a threaded piece of code), but that seems to 
conflict with the mainloop. If you start this 
application, it starts the thread, starts the mainloop 
and stays in there, once you finish the mainloop, the 
thread continues.

You've stumbled on a bug in Framework.mainloop(): it 
doesn't know anything about multiple threads. It gives 
time to other applications (by calling WaitNextEvent) 
but not to other threads within Python.

Also see
http://mail.python.org/pipermail/pythonmac-sig/2002-
April/005416.html

and 

http://mail.python.org/pipermail/pythonmac-sig/2002-
April/005428.html

----------------------------------------------------------------------

>Comment By: Jack Jansen (jackjansen)
Date: 2002-04-22 16:03

Message:
Logged In: YES 
user_id=45365

After some discussion on the SIG it turns out this is a rather complicated problem, because WNE() may cause callbacks to be called (for Carbon Event handlers, for instance), and releasing the GIL would mean those callbacks would be hosed.

A solution will have to have all callback wrappers acquire the GIL, and it will either have to make very sure we never enter WNE() or friends with the GIL held, or the callback code will need to be able to handle both the case of being called with the GIL held and the case of being called without it.

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2002-04-07 23:26

Message:
Logged In: YES 
user_id=45365

Adding an optional time.sleep(0) to the mainloop should do the trick, but unfortunately this won't work with the current MacPython, as time.sleep() is implemented with select(). And while GUSI sleep(0) does the threadswitch sleect(..., 0) doesn't. So this needs to be fixed in timemodule, and then the thread switch can be forced in Framework.Application.mainloop().

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=539990&group_id=5470