[C++-sig] subprocess fork() sometimes hangs when called from within boost::python::exec_file

Peter Schüller schueller.p at gmail.com
Mon May 4 08:45:38 CEST 2015


On Sat, May 2, 2015 at 3:43 PM, Stefan Ring <stefanrin at gmail.com> wrote:
> On Thu, Apr 2, 2015 at 9:12 PM, Peter Schüller <schueller.p at gmail.com> wrote:
>> In the hexhex project on github [1] we execute a python program using
>> boost::python::exec_file, the respective code is in
>> src/PythonPlugin.cpp in the function PythonPlugin::runPythonMain(...).
>>
>> In this python program I use subprocess.call() to run a shell
>> application (actually graphviz).
>>
>> Sometimes it works, sometimes it hangs using 100% CPU. It seems to
>> depend on how much the C++ program had to do before it executed the
>> python part. In both cases the C++ program uses threads (is that
>> relevant wrt. fork() in python? I found some hints online that it
>> could be relevant).
>>
>> I traced it down to os.fork() in subprocess.py which returns in one
>> case and does not return at all (neither parent nor child) in the
>> other case.
>>
>> If I do strace -f on the process I get the following (the
>> SIGPROF/rt_sigreturn/clone repeats until the disk is full):
>>
>> [pid 18646] clone(child_stack=0,
>> flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
>> child_tidptr=0x7f96a5fa2a50) = ? ERESTARTNOINTR (To be restarted)
>> [pid 18646] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL} ---
>> [pid 18646] rt_sigreturn()              = 56
>> [pid 18646] clone(child_stack=0,
>> flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
>> child_tidptr=0x7f96a5fa2a50) = ? ERESTARTNOINTR (To be restarted)
>> [pid 18646] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL} ---
>> [pid 18646] rt_sigreturn()              = 56
>> [pid 18646] clone(child_stack=0,
>
> There is no loop in Python's fork code, so it cannot really be blamed.
> It sure looks like there is a pending signal which interferes for some
> reason.

Thank you.

I have a signal handler for SIGINT in the program, could this interfere?
Or should I setup another signal handler?
Or is it necessary to setup signal handlers in a special way when
using boost::python?
Could you suggest a way to get more useful debugging information to
track down the problem?

Best,
Peter

-- 
http://www.peterschueller.com/


More information about the Cplusplus-sig mailing list