Debian Codegraph @

pypy/module/__pypy__/interp_signal.py

raw symbols SCIP
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 # w_exc_type can be None, but only when called from the actual
18 # PyThreadState_SetAsyncExc. in that case, the already scheduled
19 # w_async_exception_type is cancelled (of course it might or might not have
20 # been already delivered)
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 # make sure we switch away from the current thread soon, to give
26 # the target thread a chance to run
27 space.actionflag.rearm_ticker()
28 return
29 raise oefmt(space.w_ValueError, "couldn't find thread")
30