pprocess

Changeset

150:36762cec961a
2008-06-08 paulb raw files shortlog changelog graph [project @ 2008-06-08 19:35:35 by paulb] Added workaround for broken Solaris socketpair/poll using pipes.
README.txt (file) pprocess.py (file)
     1.1 --- a/README.txt	Wed Jun 04 22:13:31 2008 +0000
     1.2 +++ b/README.txt	Sun Jun 08 19:35:35 2008 +0000
     1.3 @@ -152,6 +152,8 @@
     1.4    * Added a utility function to detect and return the number of processor
     1.5      cores available.
     1.6    * Added missing documentation stylesheet.
     1.7 +  * Added support for Solaris using pipes instead of socket pairs, since
     1.8 +    the latter do not apparently work properly with poll on Solaris.
     1.9  
    1.10  New in pprocess 0.3.1 (Changes since pprocess 0.3)
    1.11  --------------------------------------------------
     2.1 --- a/pprocess.py	Wed Jun 04 22:13:31 2008 +0000
     2.2 +++ b/pprocess.py	Sun Jun 08 19:35:35 2008 +0000
     2.3 @@ -26,6 +26,7 @@
     2.4  import sys
     2.5  import select
     2.6  import socket
     2.7 +import platform
     2.8  
     2.9  try:
    2.10      import cPickle as pickle
    2.11 @@ -854,7 +855,7 @@
    2.12  
    2.13  # Low-level functions.
    2.14  
    2.15 -def create():
    2.16 +def create_socketpair():
    2.17  
    2.18      """
    2.19      Create a new process, returning a communications channel to both the
    2.20 @@ -873,6 +874,34 @@
    2.21          child.close()
    2.22          return Channel(pid, parent.makefile("r", 0), parent.makefile("w", 0))
    2.23  
    2.24 +def create_pipes():
    2.25 +
    2.26 +    """
    2.27 +    Create a new process, returning a communications channel to both the
    2.28 +    creating process and the created process.
    2.29 +
    2.30 +    This function uses pipes instead of a socket pair, since some platforms
    2.31 +    seem to have problems with poll and such socket pairs.
    2.32 +    """
    2.33 +
    2.34 +    pr, cw = os.pipe()
    2.35 +    cr, pw = os.pipe()
    2.36 +
    2.37 +    pid = os.fork()
    2.38 +    if pid == 0:
    2.39 +        pr.close()
    2.40 +        pw.close()
    2.41 +        return Channel(pid, os.fdopen(cr, "r", 0), os.fdopen(cw, "w", 0))
    2.42 +    else:
    2.43 +        cr.close()
    2.44 +        cw.close()
    2.45 +        return Channel(pid, os.fdopen(pr, "r", 0), os.fdopen(pw, "w", 0))
    2.46 +
    2.47 +if platform.system() == "SunOS":
    2.48 +    create = create_pipes
    2.49 +else:
    2.50 +    create = create_socketpair
    2.51 +
    2.52  def create_persistent(address):
    2.53  
    2.54      """