| 1 |
from pypy.interpreter.gateway import unwrap_spec |
| 2 |
from pypy.interpreter.error import oefmt |
| 3 |
from rpython.rlib.rarithmetic import r_uint |
| 4 |
|
| 5 |
|
| 6 |
def signals_enter(space): |
| 7 |
space.threadlocals.enable_signals(space) |
| 8 |
|
| 9 |
def signals_exit(space, w_ignored1=None, w_ignored2=None, w_ignored3=None): |
| 10 |
space.threadlocals.disable_signals(space) |
| 11 |
|
| 12 |
@unwrap_spec(tid=r_uint) |
| 13 |
def _raise_in_thread(space, tid, w_exc_type): |
| 14 |
""" Raise exception of type exc_type the next time the thread with id tid |
| 15 |
is resumed. Corresponds to the C-API PyThreadState_SetAsyncExc. |
| 16 |
This is an experimental API, use with care.""" |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
ecs = space.threadlocals.getallvalues() |
| 22 |
for thread_ident, ec in ecs.items(): |
| 23 |
if r_uint(thread_ident) == tid: |
| 24 |
ec.w_async_exception_type = w_exc_type |
| 25 |
|
| 26 |
|
| 27 |
space.actionflag.rearm_ticker() |
| 28 |
return |
| 29 |
raise oefmt(space.w_ValueError, "couldn't find thread") |
| 30 |
|