home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1821 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.8 KB  |  46 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import threading
  5. import inspect
  6. import ctypes
  7.  
  8. def _async_raise(tid, exctype):
  9.     if not inspect.isclass(exctype):
  10.         raise TypeError('Only types can be raised (not instances)')
  11.     inspect.isclass(exctype)
  12.     res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
  13.     if res == 0:
  14.         raise ValueError('invalid thread id')
  15.     res == 0
  16.     if res != 1:
  17.         ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
  18.         raise SystemError('PyThreadState_SetAsyncExc failed')
  19.     res != 1
  20.  
  21.  
  22. class ThreadEx(threading.Thread):
  23.     
  24.     def _get_my_tid(self):
  25.         if not self.isAlive():
  26.             raise threading.ThreadError('the thread is not active')
  27.         self.isAlive()
  28.         if hasattr(self, '_thread_id'):
  29.             return self._thread_id
  30.         for tid, tobj in threading._active.items():
  31.             if tobj is self:
  32.                 self._thread_id = tid
  33.                 return tid
  34.         
  35.         raise AssertionError("could not determine the thread's id")
  36.  
  37.     
  38.     def raise_exc(self, exctype):
  39.         _async_raise(self._get_my_tid(), exctype)
  40.  
  41.     
  42.     def kill(self):
  43.         self.raise_exc(SystemExit)
  44.  
  45.  
  46.