1 """Implements the standard thread module, using greenthreads."""
2 from eventlet.support.six.moves import _thread as __thread
3 from eventlet.support import greenlets as greenlet
4 from eventlet import greenthread
5 from eventlet.semaphore import Semaphore as LockType
8 __patched__ = ['get_ident', 'start_new_thread', 'start_new', 'allocate_lock',
9 'allocate', 'exit', 'interrupt_main', 'stack_size', '_local',
12 error = __thread.error
20 def get_ident(gr=None):
22 return id(greenlet.getcurrent())
27 def __thread_body(func, args, kwargs):
36 def start_new_thread(function, args=(), kwargs=None):
38 g = greenthread.spawn_n(__thread_body, function, args, kwargs)
42 start_new = start_new_thread
45 def allocate_lock(*a):
49 allocate = allocate_lock
53 raise greenlet.GreenletExit
56 exit_thread = __thread.exit_thread
60 curr = greenlet.getcurrent()
61 if curr.parent and not curr.parent.dead:
62 curr.parent.throw(KeyboardInterrupt())
64 raise KeyboardInterrupt()
67 if hasattr(__thread, 'stack_size'):
68 __original_stack_size__ = __thread.stack_size
70 def stack_size(size=None):
72 return __original_stack_size__()
73 if size > __original_stack_size__():
74 return __original_stack_size__(size)
77 # not going to decrease stack_size, because otherwise other greenlets in this thread will suffer
79 from eventlet.corolocal import local as _local