Re: PyObjC and multiprocessing module

Trevor Bentley <[email protected]>
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
> Multiprocessing uses fork+exec on windows, because those aren't
> separate system calls there but AFAIK you cannot force the
> multiprocessing library to do the same on Unix platforms.
> 
> Could you file a bug on python's tracker about the problem you ran
> into?  A demo program that only uses the stdlib would be great
> (possibly something using Tkinter), but isn't required.

Sure, I can file a bug with them.  Before I do that, I'd like to try to
figure out a solution.  Here's my problem:

I'm writing a cross-platform PyGTK application.  The main thread does
windowing, and there are two secondary threads: one for USB
communication (PyUSB), and one for text to speech (pyttsx).  Although I
would prefer true multiprocessing, the GIL isn't the end of the world
here, so threading will suffice.

It currently works in Linux and Windows with threading or
multiprocessing, but fails in OS X with both.  The multiprocessing
problem makes sense, it's a limitation of Apple's Foundation and
CPython's implementation.

For threading, I feel like there is probably a way to get it to work,
but I don't fully understand it.  I have traced the pyttsx code a bit,
and found what is happening:

1) When you launch the pyttsx processing loop, it calls
AppHelper.runConsoleEventLoop()
2) The sound plays correctly
3) When the utterance is finished, pyttsx stops its processing loop by
calling AppHelper.stopEventLoop()
4) In PyObjC, stopEventLoop() checks to see if there is a valid
"currentRunLoopStopper()" -- it does not find one, but does find a valid
NSApp(), which causes it to run NSApp()._terminate_() and kill my
application.

Here's another crazy tip: "import gtk" makes pyttsx stop working even in
the main thread.  Just importing it, so its module __init__ must be
doing something.

I don't fully understand NSRunLoops and how to manage them in threads,
nor the interaction between that and Python "threads".

Here's my test code: https://gist.github.com/1447666

Do you have any ideas on what I could try to get this working?

Thanks,

Trevor


------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.