Python child process in while True loop blocks parent

Cameron Simpson cs at cskk.id.au
Mon Nov 29 16:10:54 EST 2021


On 29Nov2021 21:34, Jen Kris <jenkris at tutanota.com> wrote:
>I have a C program that forks to create a child process and uses execv to call a Python program.  The Python program communicates with the parent process (in C) through a FIFO pipe monitored with epoll(). 
>
>The Python child process is in a while True loop, which is intended to keep it running while the parent process proceeds, and perform functions for the C program only at intervals when the parent sends data to the child -- similar to a daemon process. 
>
>The C process writes to its end of the pipe and the child process reads it, but then the child process continues to loop, thereby blocking the parent. 

It seems to me that the child Python process never writes anything back 
to the parent. If the parent is waiting for some response, of course it 
will be blocked.

Personally I wouldn't be using epoll at all. I'd just read data from pr, 
act on it, and write back to pw. That way the child blocks waiting for 
the parent istead of polling. You only want epoll if you're either 
polling something _while_ you do other work, or monitoring more than one 
thing. A plain read-from-one-pipe, work, write-back-to-the-other does 
not need it.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list