Bug in multiprocessing.reduction?

Yaşar Arabacı yasar11732 at gmail.com
Sat Dec 17 14:33:01 EST 2011


You can see my all code below, theoritically that code should work I guess.
But I keep getting this error:
[SUBWARNING/MainProcess] thread for sharing handles raised exception :
-------------------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/reduction.py", line 127, in _serve
send_handle(conn, handle_wanted, destination_pid)
File "/usr/lib/python2.7/multiprocessing/reduction.py", line 80, in
send_handle
_multiprocessing.sendfd(conn.fileno(), handle)
OSError: [Errno 9] Bad file descriptor
-------------------------------------------------------------------------------

Do you see an error in my side, or is this a bug in Python?

import multiprocessing as mp
import logging
import socket
import time
from random import randint
from multiprocessing.reduction import reduce_socket, rebuild_socket
logger = mp.log_to_stderr(logging.DEBUG)

def worker(queue):
      while True:
          reduced_socket = queue.get()
          # This is the line where I get  Bad file descriptor error:
          print reduced_socket[0](*reduced_socket[1])


if __name__ == '__main__':

    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind(('',9090))
    serversocket.listen(5)
    num_workers = 5
    socket_queue = mp.Queue()

    worker_processes = [mp.Process(target=worker,args=(socket_queue,)) for
i in range(num_workers)]
    for worker_process in worker_processes:
      worker_process.daemon = True
      worker_process.start()

    while True:
      client, address = serversocket.accept()
      client_handle = reduce_socket(client)
      socket_queue.put(client_handle)

-- 
http://yasar.serveblog.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111217/033b0438/attachment.html>


More information about the Python-list mailing list