コード例 #1
0
def Foo():
  thread_pool_obj = coio.thread_pool(3)
  stackless.tasklet(Sleeper)(thread_pool_obj, 9999)
  stackless.tasklet(Sleeper)(thread_pool_obj, 9999)
  stackless.tasklet(Sleeper)(thread_pool_obj, 2)
  stackless.schedule()
  f = lambda a, b: time.sleep(0.2) or a / b
  #f = lambda a, b: a / b
  #f = lambda a, b: sys.exit(42)
  print 'X0'
  if False:
    for i in xrange(1, 11):
      print i
      assert 42 == worker(f, 84 * i, 2 * i)
  print 'X1'
  # This first call is slow (takes about 2 seconds), because we have to wait for
  # a Sleeper to return.
  print thread_pool_obj(f, -42, -1)
  print 'X2'
  print thread_pool_obj(f, -42, -1)
  print 'X3'
  print thread_pool_obj(f, -42, -1)
  #print 'T'
  #time.sleep(10)
  print 'X4'
  try:
    thread_pool_obj(f, 7, 0)
    e = None
  except ZeroDivisionError, e:
    pass
コード例 #2
0
def Foo():
    thread_pool_obj = coio.thread_pool(3)
    stackless.tasklet(Sleeper)(thread_pool_obj, 9999)
    stackless.tasklet(Sleeper)(thread_pool_obj, 9999)
    stackless.tasklet(Sleeper)(thread_pool_obj, 2)
    stackless.schedule()
    f = lambda a, b: time.sleep(0.2) or a / b
    #f = lambda a, b: a / b
    #f = lambda a, b: sys.exit(42)
    print 'X0'
    if False:
        for i in xrange(1, 11):
            print i
            assert 42 == worker(f, 84 * i, 2 * i)
    print 'X1'
    # This first call is slow (takes about 2 seconds), because we have to wait for
    # a Sleeper to return.
    print thread_pool_obj(f, -42, -1)
    print 'X2'
    print thread_pool_obj(f, -42, -1)
    print 'X3'
    print thread_pool_obj(f, -42, -1)
    #print 'T'
    #time.sleep(10)
    print 'X4'
    try:
        thread_pool_obj(f, 7, 0)
        e = None
    except ZeroDivisionError, e:
        pass
コード例 #3
0
seconds, because a thread pool of size 3 will be used by 4 threads doing
a sleep of 2 seconds each, so the last sleep can only be started after the
first thread has finished.
"""

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

import sys
import time

from syncless.best_stackless import stackless
from syncless import coio


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


if __name__ == '__main__':
    stackless.tasklet(ProgressReporter)(0.05)
    thread_pool_obj = coio.thread_pool(4 - bool(len(sys.argv) > 1))
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    sys.stderr.write('S')
    stackless.schedule()
    thread_pool_obj(time.sleep, 2)
    sys.stderr.write('D\n')
コード例 #4
0
seconds, because a thread pool of size 3 will be used by 4 threads doing
a sleep of 2 seconds each, so the last sleep can only be started after the
first thread has finished.
"""

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

import sys
import time

from syncless.best_stackless import stackless
from syncless import coio


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


if __name__ == "__main__":
    stackless.tasklet(ProgressReporter)(0.05)
    thread_pool_obj = coio.thread_pool(4 - bool(len(sys.argv) > 1))
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    stackless.tasklet(thread_pool_obj)(time.sleep, 2)
    sys.stderr.write("S")
    stackless.schedule()
    thread_pool_obj(time.sleep, 2)
    sys.stderr.write("D\n")