multiprocessing

python multiprocessing vs threading for cpu bound work on windows and linux

So I knocked up some test code to see how the multiprocessing module would scale on cpu bound work compared to threading. On linux I get the performance increase that I'd expect: linux (dual quad core xeon): serialrun took 1192.319 ms parallelrun took 346.727 ms threadedrun took 2108.172 ms My dual core macbook pro shows the same beha...

accept() with sockets shared between multiple processes (based on Apache preforking)

I'm working on some Python code modeled on Apache's MPM prefork server. I am more an applications programmer than a network programmer and it's been 10 years since I read Stevens, so I'm trying to get up to speed in understanding the code. I found a short description of how Apache's prefork code works, by Sander Temme. The parent pr...

Multiprocessing with renewable queue

I'm trying to figure out how to write a program in python that uses the multiprocessing queue. I have multiple servers and one of them will provide the queue remotely with this: from multiprocessing.managers import BaseManager import Queue import daemonme queue = Queue.Queue() class QueueManager(BaseManager): pass daemonme.creat...

Python multiprocessing for bulk file/conversion operation on Windows

I have written a python script which watches a directory for new subdirectories, and then acts on each subdirectory in a loop. We have an external process which creates these subdirectories. Inside each subdirectory is a text file and a number of images. There is one record (line) in the text file for each image. For each subdirector...

Multiprocessing debug techniques

I'm having trouble debugging a multi-process application (specifically using a process pool in python's multiprocessing module). I have an apparent deadlock and I do not know what is causing it. The stack trace is not sufficient to describe the issue, as it only displays code in the multiprocessing module. Are there any python tools, or...

RPC for multiprocessing, design issues

Hey everyone, what's a good way to do rpc across multiprocessing.Process'es ? I am also open to design advise on the following architecture: Process A * 10, Process B * 1. Each process A has to check with proces B on whether a particular item needs to be queried. So I was thinking of implementing multiprocessing.Pipe() object for all...

any body familiar with how I can implement a multiprocessing priority queue in python?

any body familiar with how I can implement a multiprocessing priority queue in python? ...

Error while using multiprocessing module in a python daemon

I'm getting the following error when using the multiprocessing module within a python daemon process (using python-daemon): Traceback (most recent call last): File "/usr/local/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.6/multiprocessing/util.py", line 262, in _exit_fu...

Python multiprocessing with twisted's reactor

Dear everyone I am working on a xmlrpc server which has to perform certain tasks cyclically. I am using twisted as the core of the xmlrpc service but I am running into a little problem: class cemeteryRPC(xmlrpc.XMLRPC): def __init__(self, dic): xmlrpc.XMLRPC.__init__(self) def xmlrpc_foo(self): return 1 ...

Multiple fork() Concurrency

How do you use the fork() command in such a way that you can spawn 10 processes and have them do a small task concurrently. Concurrent is the operative word, many places that show how to use fork only use one call to fork() in their demos. I thought you would use some kind of for loop but i tried and it seems in my tests that the fork()...

Multiprocessor Scheduling Algorithm

Hi, I'm searching for a Sequential implementation of multiprocessor scheduling algorithm, preferably implemented in c++, or c. Any suggestions are welcome. ...

Keyboard Interrupts with python's multiprocessing Pool

How can I handle KeyboardInterrupt events with python's multiprocessing Pools? Here is a simple example: from multiprocessing import Pool from time import sleep from sys import exit def slowly_square(i): sleep(1) return i*i def go(): pool = Pool(8) try: results = pool.map(slowly_square, range(40)) except Ke...

How can you profile a parallelized Python script?

Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize several things and I run it with the following command: python -m cProfile my_parallel_script.py This generates profiling output for the parent process only. Calls made in child processes are not recorded at all. Is it possib...

Profiling a python multiprocessing pool

I'm trying to run cProfile.runctx() on each process in a multiprocessing pool, to get an idea of what the multiprocessing bottlenecks are in my source. Here is a simplified example of what I'm trying to do: from multiprocessing import Pool import cProfile def square(i): return i*i def square_wrapper(i): cProfile.runctx("result...

Python 2.6 send connection object over Queue / Pipe / etc.

Given this bug (Python Issue 4892) that gives rise to the following error: >>> import multiprocessing >>> multiprocessing.allow_connection_pickling() >>> q = multiprocessing.Queue() >>> p = multiprocessing.Pipe() >>> q.put(p) >>> q.get() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/.../python2.6/...

InterlockedIncrement vs. ++

How does InterlockedIncrement work? Is the concern only on multi-processor systems? What does it do, disable interrupts across all processors? ...

With python.multiprocessing, how do I create a proxy in the current process to pass to other processes?

I'm using the multiprocessing library in Python. I can see how to define that objects returned from functions should have proxies created, but I'd like to have objects in the current process turned into proxies so I can pass them as parameters. For example, running the following script: from multiprocessing import current_process from...

Twisted network client with multiprocessing workers?

So, I've got an application that uses Twisted + Stomper as a STOMP client which farms out work to a multiprocessing.Pool of workers. This appears to work ok when I just use a python script to fire this up, which (simplified) looks something like this: # stompclient.py logging.config.fileConfig(config_path) logger = logging.getLogger(_...

python multiprocessing manager & composite pattern sharing

I'm trying to share a composite structure through a multiprocessing manager but I felt in trouble with a "RuntimeError: maximum recursion depth exceeded" when trying to use just one of the Composite class methods. The class is token from code.activestate and tested by me before inclusion into the manager. When retrieving the class into...

Synchronize shell script execution

A modified version of a shell script converts an audio file from FLAC to MP3 format. The computer has a quad-core CPU. The script is run using: ./flac2mp3.sh $(find flac -type f) This converts the FLAC files in the flac directory (no spaces in file names) to MP3 files in the mp3 directory (at the same level as flac). If the destinatio...