1.1 --- a/pprocess.py Wed Jun 04 22:13:31 2008 +0000
1.2 +++ b/pprocess.py Sun Jun 08 19:35:35 2008 +0000
1.3 @@ -26,6 +26,7 @@
1.4 import sys
1.5 import select
1.6 import socket
1.7 +import platform
1.8
1.9 try:
1.10 import cPickle as pickle
1.11 @@ -854,7 +855,7 @@
1.12
1.13 # Low-level functions.
1.14
1.15 -def create():
1.16 +def create_socketpair():
1.17
1.18 """
1.19 Create a new process, returning a communications channel to both the
1.20 @@ -873,6 +874,34 @@
1.21 child.close()
1.22 return Channel(pid, parent.makefile("r", 0), parent.makefile("w", 0))
1.23
1.24 +def create_pipes():
1.25 +
1.26 + """
1.27 + Create a new process, returning a communications channel to both the
1.28 + creating process and the created process.
1.29 +
1.30 + This function uses pipes instead of a socket pair, since some platforms
1.31 + seem to have problems with poll and such socket pairs.
1.32 + """
1.33 +
1.34 + pr, cw = os.pipe()
1.35 + cr, pw = os.pipe()
1.36 +
1.37 + pid = os.fork()
1.38 + if pid == 0:
1.39 + pr.close()
1.40 + pw.close()
1.41 + return Channel(pid, os.fdopen(cr, "r", 0), os.fdopen(cw, "w", 0))
1.42 + else:
1.43 + cr.close()
1.44 + cw.close()
1.45 + return Channel(pid, os.fdopen(pr, "r", 0), os.fdopen(pw, "w", 0))
1.46 +
1.47 +if platform.system() == "SunOS":
1.48 + create = create_pipes
1.49 +else:
1.50 + create = create_socketpair
1.51 +
1.52 def create_persistent(address):
1.53
1.54 """