Tensorflow and Multiprocessing: Passing Sessions

You can’t use Python multiprocessing to pass a TensorFlow Session into a multiprocessing.Pool in the straightfoward way because the Session object can’t be pickled (it’s fundamentally not serializable because it may manage GPU memory and state like that). I’d suggest parallelizing the code using actors, which are essentially the parallel computing analog of “objects” and … Read more

Understanding Multiprocessing: Shared Memory Management, Locks and Queues in Python

multiprocessing.Lock is implemented using a Semaphore object provided by the OS. On Linux, the child just inherits a handle to the Semaphore from the parent via os.fork. This isn’t a copy of the semaphore; it’s actually inheriting the same handle the parent has, the same way file descriptors can be inherited. Windows on the other … Read more

Understanding Multiprocessing: Shared Memory Management, Locks and Queues in Python

multiprocessing.Lock is implemented using a Semaphore object provided by the OS. On Linux, the child just inherits a handle to the Semaphore from the parent via os.fork. This isn’t a copy of the semaphore; it’s actually inheriting the same handle the parent has, the same way file descriptors can be inherited. Windows on the other … Read more

Using multiprocessing.Process with a maximum number of simultaneous processes

It might be most sensible to use multiprocessing.Pool which produces a pool of worker processes based on the max number of cores available on your system, and then basically feeds tasks in as the cores become available. The example from the standard docs (http://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers) shows that you can also manually set the number of cores: … Read more

Python multiprocessing application is getting stuck in docker container

Two approaches: try concurrent.futures process executor Different libraries handle cases like these differently. Might fail more gracefully under your specific circumstances. psutils and manual memory allocation logging If you are building this into a production process, this is a must given errors you’ve encountered so far.