Exemplo n.º 1
0
 def testWithPatch(self):
   patch.patch_os()
   assert os.fork is not unpatched_fork
   a, b = coio.socketpair()
   pid = os.fork()
   if pid:  # Parent.
     try:
       a = a.dup()
       b = b.dup()
       RunWorker(b, a, self.MAX_SIZE)
     finally:
       got_pid, status = os.waitpid(pid, 0)
       assert got_pid == pid
     assert status == 0, 'child exited with status 0x%x' % status
   else:
     try:
       # No need for coio.reinit(), our patched fork does that.
       RunWorker(a, b, self.MAX_SIZE)
       os._exit(0)
     except:
       sys.stderr.write(sys.exc_info())
       os._exit(1)
Exemplo n.º 2
0
# by [email protected] at Mon Apr 19 02:16:27 CEST 2010

"""Demo for communicating with children via subprocess in non-blocking way."""

__author__ = '[email protected] (Peter Szabo)'

import subprocess
import sys

from syncless import coio
from syncless import patch

def ProgressReporter(delta_sec):
  while True:
    sys.stderr.write('.')
    coio.sleep(delta_sec)

if __name__ == "__main__":
  # Without this patch_...() call the ProgressReporter wouldn't be scheduled,
  # and thus the progress dots wouldn't be printed.
  if len(sys.argv) > 1:
    patch.patch_os()
  else:
    patch.patch_subprocess()
  coio.stackless.tasklet(ProgressReporter)(0.05)
  p = subprocess.Popen('sleep 1; ps x', stdout=subprocess.PIPE, shell=True,
                       close_fds=True)
  for line in p.stdout:
    print repr(line)
  print 'returncode = %d' % p.wait()
Exemplo n.º 3
0
__author__ = '[email protected] (Peter Szabo)'

import warnings
warnings.simplefilter('ignore', DeprecationWarning)  # for popen2

import popen2
import sys

from syncless import coio
from syncless import patch


def ProgressReporter(delta_sec):
    while True:
        sys.stderr.write('.')
        coio.sleep(delta_sec)


if __name__ == "__main__":
    # Without this patch_...() call the ProgressReporter wouldn't be scheduled,
    # and thus the progress dots wouldn't be printed.
    if len(sys.argv) > 1:
        patch.patch_os()
    else:
        patch.patch_popen2()
    coio.stackless.tasklet(ProgressReporter)(0.05)
    r, w = popen2.popen2('sleep 1; ps x')
    for line in r:
        print repr(line)
    print 'bye'