Comments appreciated on Erlang inspired Process class.

Nick Craig-Wood nick at
Mon Jun 4 11:30:05 CEST 2007

Brian L. Troutwine <goofyheadedpunk at> wrote:
>  Lately I've been tinkering around with Erlang and have begun to sorely want 
>  some of its features in Python, mostly the ease at which new processes can be 
>  forked off for computation. To that end I've coded up a class I call, 
>  boringly enough, Process. It takes a function, its args and keywords and runs 
>  the function in another process using os.fork. Processes can be treated as 
>  callables to retrieve the return value of the passed in function.
>  The code is pasted here: A simple 
>  exposition of Process is included at the end of the code in some __main__ 
>  magic. (Note: The code will not run on any system which lacks os.fork and 
>  spawns 100 child processes while running.)
>  I'd very much appreciate people to look the code over and give me their 
>  reactions to it, or suggests for improvement. As it stands, I see three major 
>  defects with the current implementation: 
>  	1) Process hangs forever if its child errors out.
>  	2) Process isn't portable because of its use of os.fork().
>  	3) Process should use AF_UNIX when available instead of TCP.

You could use os.pipe() or socket.socketpair().  It would simplify the
code a lot too!

The biggest problem I see is that there is no non-blocking way of
seeing whether the Process() has finished or not, and no way to wait
on more than one Process() at once.

If there is an exception then you should return it to the parent (see
the subprocess module for an example).

Nick Craig-Wood <nick at> --

More information about the Python-list mailing list