[capi-sig] embedding vs. multiprocessing

Kurt Sutter kurt at quansoft.com
Fri Jun 5 06:50:03 CEST 2009


Dear list

We have a GUI-based application written basically in C. The  
application allows the user to embed Python scripts, e.g. for  
scripting some functionality of the application.

Some of our users are interested in running multiprocessing Python  
code. We have found that this does not work, bringing up various types  
of errors, depending on how the script invokes multiprocessing.

I have tried to isolate the issue, and found that the following simple  
C-code fails:

	Py_Initialize();

	const char* script =
		"from multiprocessing import Process\n"
		"import os, time\n"
		"def sleeper(name, seconds):\n"
		"    time.sleep(seconds)\n"	
		"p = Process(target=sleeper, args=('bob', 1))\n"
		"print 'starting child process'\n"
		"p.start()\n"
		"print 'joining'\n"
		"p.join()\n"
		"print 'done'\n";
	PyRun_SimpleString(script);

with the following output:

starting child process
joining
Traceback (most recent call last):
   File "<string>", line 9, in <module>
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/multiprocessing/process.py", line 119, in join
     res = self._popen.wait(timeout)
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/multiprocessing/forking.py", line 117, in wait
     return self.poll(0)
   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
python2.6/multiprocessing/forking.py", line 106, in poll
     pid, sts = os.waitpid(self.pid, flag)
OSError: [Errno 4] Interrupted system call

The same Python script, when saved as a .py file and invoked from the  
console, works fine.

System information: MacOS 10.5.6, Pyton 2.6.2.

Thanks for any advice in advance.

Kurt Sutter
QuantumSoft




More information about the capi-sig mailing list