File: interp_signal.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (29 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.error import oefmt


def signals_enter(space):
    space.threadlocals.enable_signals(space)

def signals_exit(space, w_ignored1=None, w_ignored2=None, w_ignored3=None):
    space.threadlocals.disable_signals(space)

@unwrap_spec(tid=int)
def _raise_in_thread(space, tid, w_exc_type):
    """ Raise exception of type exc_type the next time the thread with id tid
    is resumed. Corresponds to the C-API PyThreadState_SetAsyncExc.
    This is an experimental API, use with care."""
    # w_exc_type can be None, but only when called from the actual
    # PyThreadState_SetAsyncExc. in that case, the already scheduled
    # w_async_exception_type is cancelled (of course it might or might not have
    # been already delivered)
    ecs = space.threadlocals.getallvalues()
    for thread_ident, ec in ecs.items():
        if thread_ident == tid:
            ec.w_async_exception_type = w_exc_type
            # make sure we switch away from the current thread soon, to give
            # the target thread a chance to run
            space.actionflag.rearm_ticker()
            return
    raise oefmt(space.w_ValueError, "couldn't find thread")