home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / dummy_thread.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  2.8 KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. __all__ = [
  5.     'error',
  6.     'start_new_thread',
  7.     'exit',
  8.     'get_ident',
  9.     'allocate_lock',
  10.     'interrupt_main',
  11.     'LockType']
  12. import traceback as _traceback
  13.  
  14. class error(Exception):
  15.     
  16.     def __init__(self, *args):
  17.         self.args = args
  18.  
  19.  
  20.  
  21. def start_new_thread(function, args, kwargs = { }):
  22.     global _main, _main, _interrupt
  23.     if type(args) != type(tuple()):
  24.         raise TypeError('2nd arg must be a tuple')
  25.     if type(kwargs) != type(dict()):
  26.         raise TypeError('3rd arg must be a dict')
  27.     _main = False
  28.     
  29.     try:
  30.         function(*args, **kwargs)
  31.     except SystemExit:
  32.         pass
  33.     except:
  34.         _traceback.print_exc()
  35.  
  36.     _main = True
  37.     if _interrupt:
  38.         _interrupt = False
  39.         raise KeyboardInterrupt
  40.  
  41.  
  42. def exit():
  43.     raise SystemExit
  44.  
  45.  
  46. def get_ident():
  47.     return -1
  48.  
  49.  
  50. def allocate_lock():
  51.     return LockType()
  52.  
  53.  
  54. def stack_size(size = None):
  55.     if size is not None:
  56.         raise error('setting thread stack size not supported')
  57.     return 0
  58.  
  59.  
  60. class LockType(object):
  61.     
  62.     def __init__(self):
  63.         self.locked_status = False
  64.  
  65.     
  66.     def acquire(self, waitflag = None):
  67.         if waitflag is None or waitflag:
  68.             self.locked_status = True
  69.             return True
  70.         if not None.locked_status:
  71.             self.locked_status = True
  72.             return True
  73.         return None
  74.  
  75.     __enter__ = acquire
  76.     
  77.     def __exit__(self, typ, val, tb):
  78.         self.release()
  79.  
  80.     
  81.     def release(self):
  82.         if not self.locked_status:
  83.             raise error
  84.         self.locked_status = False
  85.         return True
  86.  
  87.     
  88.     def locked(self):
  89.         return self.locked_status
  90.  
  91.  
  92. _interrupt = False
  93. _main = True
  94.  
  95. def interrupt_main():
  96.     global _interrupt
  97.     if _main:
  98.         raise KeyboardInterrupt
  99.     _interrupt = True
  100.  
  101.