Search code examples
pythonpylonsmultiprocessing

Process() called from from Pylons creates a fork


I'm trying to create a background process for some heavy calculations from the main Pylons process. Here's the code:

    p = Process(target = instance_process, \
                args = (instance_tuple.instance, parent_pipe, child_pipe,))
    p.start()

The process is created and started, but is seems to be a fork from the main process: it is listening to the same port and the whole application hangs up. What am I doing wrong?

Thanks in advance.


Solution

  • Process IS a fork. If you look through it's implementation you'll find that Process.start() calls a fork. It does NOT, however, call any of the exec variations to change the execution context.

    Still, this may have nothing to do with listening on the same port (unless the parent process is multi-threaded). At which point is the program hanging? I know that when you try shutting down a python program without terminating the child process created through multiprocessing it will hang until the child process terminates. This might be caused if, for instance, you do not close the pipe between the processes.