--- threading.py.standard	2007-07-01 10:10:01.000000000 +0200
+++ threading.py	2007-07-01 11:19:22.000000000 +0200
@@ -23,6 +23,33 @@
 ThreadError = thread.error
 del thread
 
+# Thread killing stuff from "Paste.util.killthread"
+
+import types
+try:
+    import ctypes
+except ImportError:
+    ctypes = None
+    
+def async_raise(thread_id, exctype):
+    """raises the exception, performs cleanup if needed.
+
+    tid is the value given by thread.get_ident() (an integer).
+    Raise SystemExit to kill a thread."""
+    assert ctypes, "You cannot use async_raise without ctypes installed"
+    
+    if not isinstance(exctype, (types.ClassType, type)):
+        raise TypeError("Only types can be raised (not instances)")
+    if not isinstance(thread_id, int):
+        raise TypeError("thread_id must be an integer")
+    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, ctypes.py_object(exctype))
+    if res == 0:
+        raise ValueError("invalid thread id")
+    elif res != 1:
+        # """if it returns a number greater than one, you're in trouble, 
+        # and you should call it again with exc=NULL to revert the effect"""
+        ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0)
+        raise SystemError("PyThreadState_SetAsyncExc failed")
 
 # Debug support (adapted from ihooks.py).
 # All the major classes here derive from _Verbose.  We force that to
@@ -389,7 +416,8 @@
         # sys.stderr is not stored in the class like
         # sys.exc_info since it can be changed between instances
         self.__stderr = _sys.stderr
-
+        self.__thread_id = None
+        
     def _set_daemon(self):
         # Overridden in _MainThread and _DummyThread
         return currentThread().isDaemon()
@@ -413,7 +441,7 @@
         _active_limbo_lock.acquire()
         _limbo[self] = self
         _active_limbo_lock.release()
-        _start_new_thread(self.__bootstrap, ())
+        self.__thread_id = _start_new_thread(self.__bootstrap, ())
         self.__started = True
         _sleep(0.000001)    # 1 usec, to let the thread run (Solaris hack)
 
@@ -421,6 +449,15 @@
         if self.__target:
             self.__target(*self.__args, **self.__kwargs)
 
+    def kill (self, exctype=None):
+        if exctype is None:
+            exctype = SystemExit
+        if self.__thread_id and self.__started:
+            async_raise (self.__thread_id, exctype)
+            
+    def getThreadID (self):
+        return self.__thread_id
+    
     def __bootstrap(self):
         try:
             self.__started = True
