| 1 |
|
| 2 |
|
| 3 |
from pypy.interpreter.mixedmodule import MixedModule |
| 4 |
|
| 5 |
class Module(MixedModule): |
| 6 |
applevel_name = '_thread' |
| 7 |
|
| 8 |
appleveldefs = { |
| 9 |
} |
| 10 |
|
| 11 |
interpleveldefs = { |
| 12 |
'start_new_thread': 'os_thread.start_new_thread', |
| 13 |
'start_new': 'os_thread.start_new_thread', |
| 14 |
'get_ident': 'os_thread.get_ident', |
| 15 |
'get_native_id': 'os_thread.get_native_id', |
| 16 |
'exit': 'os_thread.exit', |
| 17 |
'exit_thread': 'os_thread.exit', |
| 18 |
'interrupt_main': 'os_thread.interrupt_main', |
| 19 |
'stack_size': 'os_thread.stack_size', |
| 20 |
'_count': 'os_thread._count', |
| 21 |
'allocate_lock': 'os_lock.allocate_lock', |
| 22 |
'allocate': 'os_lock.allocate_lock', |
| 23 |
'LockType': 'os_lock.Lock', |
| 24 |
'RLock': 'os_lock.W_RLock', |
| 25 |
'_set_sentinel': 'os_lock._set_sentinel', |
| 26 |
'_local': 'os_local.Local', |
| 27 |
'TIMEOUT_MAX': 'space.wrap(float(os_lock.TIMEOUT_MAX // 1000000))', |
| 28 |
'error': 'space.w_RuntimeError', |
| 29 |
} |
| 30 |
|
| 31 |
def __init__(self, space, *args): |
| 32 |
"NOT_RPYTHON: patches space.threadlocals to use real threadlocals" |
| 33 |
from pypy.module.thread import gil |
| 34 |
MixedModule.__init__(self, space, *args) |
| 35 |
prev_ec = space.threadlocals.get_ec() |
| 36 |
space.threadlocals = gil.GILThreadLocals(space) |
| 37 |
space.threadlocals.initialize(space) |
| 38 |
if prev_ec is not None: |
| 39 |
space.threadlocals._set_ec(prev_ec) |
| 40 |
|
| 41 |
from pypy.module.posix.interp_posix import add_fork_hook |
| 42 |
from pypy.module.thread.os_thread import reinit_threads |
| 43 |
add_fork_hook('child', reinit_threads) |