Thread: [Pyobjc-dev] PyObjC and multiprocessing module
Brought to you by:
ronaldoussoren
From: Trevor B. <mr...@gm...> - 2011-12-07 22:54:08
|
I found a bunch of hits for this on Google, but no answers: I am working on a Python application that uses the multiprocessing library. I am trying to spawn a process and perform text-to-speech with pyttsx, but I get the dreaded __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() error. Is there any way to get this working, short of switching back to threads? I see that the 'correct' way is to fork() and exec(), but I don't see any way to make that compatible with the multiprocessing module's API. Thanks, -Trevor |
From: Aahz <aa...@py...> - 2011-12-08 00:05:01
|
On Wed, Dec 07, 2011, Trevor Bentley wrote: > > I found a bunch of hits for this on Google, but no answers: > > I am working on a Python application that uses the multiprocessing library. > I am trying to spawn a process and perform text-to-speech with pyttsx, but > I get the > dreaded __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() > error. > > Is there any way to get this working, short of switching back to threads? > I see that the 'correct' way is to fork() and exec(), but I don't see any > way to make that compatible with the multiprocessing module's API. You could do something other than multiprocessing module to access another process (socket to me!). Depends how much a problem the GIL is for you. -- Aahz (aa...@py...) <*> http://www.pythoncraft.com/ "....Normal is what cuts off your sixth finger and your tail..." --Siobhan |
From: Ronald O. <ron...@ma...> - 2011-12-08 15:07:25
Attachments:
smime.p7s
|
On 7 Dec, 2011, at 23:54, Trevor Bentley wrote: > I found a bunch of hits for this on Google, but no answers: > > I am working on a Python application that uses the multiprocessing library. I am trying to spawn a process and perform text-to-speech with pyttsx, but I get the dreaded __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() error. Most of Apple's frameworks beyond the basic Unix tools require that you child proceses immediately call execv() instead of forking of a child and doing work there as multiprocessing does. > > Is there any way to get this working, short of switching back to threads? I see that the 'correct' way is to fork() and exec(), but I don't see any way to make that compatible with the multiprocessing module's API. 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. Ronald > > 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/_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Trevor B. <mr...@gm...> - 2011-12-08 17:14:52
|
> 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 |