home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / multiprocessing / dummy / __init__.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.3 KB  |  138 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'Process',
  6.     'current_process',
  7.     'active_children',
  8.     'freeze_support',
  9.     'Lock',
  10.     'RLock',
  11.     'Semaphore',
  12.     'BoundedSemaphore',
  13.     'Condition',
  14.     'Event',
  15.     'Queue',
  16.     'Manager',
  17.     'Pipe',
  18.     'Pool',
  19.     'JoinableQueue']
  20. import threading
  21. import sys
  22. import weakref
  23. import array
  24. import itertools
  25. from multiprocessing import TimeoutError, cpu_count
  26. from multiprocessing.dummy.connection import Pipe
  27. from threading import Lock, RLock, Semaphore, BoundedSemaphore
  28. from threading import Event
  29. from Queue import Queue
  30.  
  31. class DummyProcess(threading.Thread):
  32.     
  33.     def __init__(self, group = None, target = None, name = None, args = (), kwargs = { }):
  34.         threading.Thread.__init__(self, group, target, name, args, kwargs)
  35.         self._pid = None
  36.         self._children = weakref.WeakKeyDictionary()
  37.         self._start_called = False
  38.         self._parent = current_process()
  39.  
  40.     
  41.     def start(self):
  42.         if not self._parent is current_process():
  43.             raise AssertionError
  44.         self._start_called = True
  45.         self._parent._children[self] = None
  46.         threading.Thread.start(self)
  47.  
  48.     
  49.     def exitcode(self):
  50.         if self._start_called and not self.is_alive():
  51.             return 0
  52.         return None
  53.  
  54.     exitcode = property(exitcode)
  55.  
  56.  
  57. class Condition(threading._Condition):
  58.     notify_all = threading._Condition.notify_all.im_func
  59.  
  60. Process = DummyProcess
  61. current_process = threading.current_thread
  62. current_process()._children = weakref.WeakKeyDictionary()
  63.  
  64. def active_children():
  65.     children = current_process()._children
  66.     for p in list(children):
  67.         if not p.is_alive():
  68.             children.pop(p, None)
  69.             continue
  70.     
  71.     return list(children)
  72.  
  73.  
  74. def freeze_support():
  75.     pass
  76.  
  77.  
  78. class Namespace(object):
  79.     
  80.     def __init__(self, **kwds):
  81.         self.__dict__.update(kwds)
  82.  
  83.     
  84.     def __repr__(self):
  85.         items = self.__dict__.items()
  86.         temp = []
  87.         for name, value in items:
  88.             if not name.startswith('_'):
  89.                 temp.append('%s=%r' % (name, value))
  90.                 continue
  91.         
  92.         temp.sort()
  93.         return 'Namespace(%s)' % str.join(', ', temp)
  94.  
  95.  
  96. dict = dict
  97. list = list
  98.  
  99. def Array(typecode, sequence, lock = True):
  100.     return array.array(typecode, sequence)
  101.  
  102.  
  103. class Value(object):
  104.     
  105.     def __init__(self, typecode, value, lock = True):
  106.         self._typecode = typecode
  107.         self._value = value
  108.  
  109.     
  110.     def _get(self):
  111.         return self._value
  112.  
  113.     
  114.     def _set(self, value):
  115.         self._value = value
  116.  
  117.     value = property(_get, _set)
  118.     
  119.     def __repr__(self):
  120.         return '<%r(%r, %r)>' % (type(self).__name__, self._typecode, self._value)
  121.  
  122.  
  123.  
  124. def Manager():
  125.     return sys.modules[__name__]
  126.  
  127.  
  128. def shutdown():
  129.     pass
  130.  
  131.  
  132. def Pool(processes = None, initializer = None, initargs = ()):
  133.     ThreadPool = ThreadPool
  134.     import multiprocessing.pool
  135.     return ThreadPool(processes, initializer, initargs)
  136.  
  137. JoinableQueue = Queue
  138.