1.1 --- a/parallel.py Wed Sep 28 15:44:53 2005 +0000
1.2 +++ b/parallel.py Wed Sep 28 15:56:36 2005 +0000
1.3 @@ -92,6 +92,7 @@
1.4 import os
1.5 import sys
1.6 import select
1.7 +import socket
1.8 #from signal import signal, SIGCHLD
1.9
1.10 try:
1.11 @@ -175,7 +176,7 @@
1.12 self.poller = select.poll()
1.13 for channel in channels:
1.14 self.readables[channel.read_pipe.fileno()] = channel
1.15 - self.poller.register(channel.read_pipe.fileno(), select.POLLIN | select.POLLOUT | select.POLLHUP | select.POLLNVAL | select.POLLERR)
1.16 + self.poller.register(channel.read_pipe.fileno(), select.POLLIN | select.POLLHUP | select.POLLNVAL | select.POLLERR)
1.17
1.18 def active(self):
1.19
1.20 @@ -203,7 +204,7 @@
1.21
1.22 # Remove ended/error channels.
1.23
1.24 - if status & (select.POLLOUT | select.POLLHUP | select.POLLNVAL | select.POLLERR):
1.25 + if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
1.26 self.remove(channel)
1.27
1.28 return readables
1.29 @@ -224,18 +225,20 @@
1.30 creating process and the created process.
1.31 """
1.32
1.33 - parent_read_fd, child_write_fd = os.pipe()
1.34 - child_read_fd, parent_write_fd = os.pipe()
1.35 + parent_read, child_write = socket.socketpair()
1.36 + child_read, parent_write = socket.socketpair()
1.37 + for s in [parent_read, child_write, child_read, parent_write]:
1.38 + s.setblocking(1)
1.39
1.40 pid = os.fork()
1.41 if pid == 0:
1.42 - os.close(parent_read_fd)
1.43 - os.close(parent_write_fd)
1.44 - return Channel(pid, os.fdopen(child_read_fd, "r"), os.fdopen(child_write_fd, "w"))
1.45 + parent_read.close()
1.46 + parent_write.close()
1.47 + return Channel(pid, child_read.makefile("r"), child_write.makefile("w"))
1.48 else:
1.49 - os.close(child_read_fd)
1.50 - os.close(child_write_fd)
1.51 - return Channel(pid, os.fdopen(parent_read_fd, "r"), os.fdopen(parent_write_fd, "w"))
1.52 + child_read.close()
1.53 + child_write.close()
1.54 + return Channel(pid, parent_read.makefile("r"), parent_write.makefile("w"))
1.55
1.56 def start(callable, *args, **kwargs):
1.57