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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
U
Z±dì ã@s€ddlmZddlZddlZddlmZddlmZddlm    Z    ej
dd    Gd
d „d ƒƒZ ej
d d dd Gdd„dedƒZ dS)é)ÚdequeNé)Ú_core)ÚNoPublicConstructoré)ÚWakeupSocketpairT)Úslotsc@speZdZejedZejedZeje    dZ
ejddZ eje j dZdd„Zdd„Zdd    „Zdd
œd d „Zd S)Ú
EntryQueue)ÚfactoryF)Údefaultc ƒsºt ¡s t‚ˆjjjdkst‚dd„‰‡‡fdd„}z8|ƒˆjsZˆjsZˆj     ¡IdHq6t 
¡IdHq6WnHtj k
r´ˆj dˆ_ W5QRX|ƒˆjr¦t‚ˆjr°t‚YnXdS)NÚ_threadc Ss||\}}z ||ŽWnbtk
rv}zDdd„}zt ||¡Wn&tk
rdt ¡j ||¡YnXW5d}~XYnXdS)NcÓs|‚dS©N©)ÚexcrrúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_core/_entry_queue.pyÚkill_everything8sz8EntryQueue.task.<locals>.run_cb.<locals>.kill_everythingT)Ú BaseExceptionrZspawn_system_taskÚ RuntimeErrorZ current_taskZparent_nurseryZ
start_soon)ÚjobÚsync_fnÚargsrrrrrÚrun_cb.s *zEntryQueue.task.<locals>.run_cbcsFttˆjƒƒD]}ˆˆj ¡ƒqtˆjƒD]}ˆj|=ˆ|ƒq,dSr )ÚrangeÚlenÚqueueÚpopleftÚlistÚidempotent_queue)Ú_r©rÚselfrrÚrun_all_boundedIs
z(EntryQueue.task.<locals>.run_all_boundedT) rZcurrently_ki_protectedÚAssertionErrorÚlockÚ    __class__Ú
__module__rrÚwakeupZ
wait_wokenÚ
checkpointZ    CancelledÚdone)r r!rrrÚtask#s   
zEntryQueue.taskcCs|j ¡dSr )r&Úclose©r rrrr*kszEntryQueue.closecCst|jƒt|jƒSr )rrrr+rrrÚsizenszEntryQueue.size©Ú
idempotentc    GsT|jD|jrt d¡‚|r,d|j||f<n|j ||f¡|j ¡W5QRXdS)Nzrun() has exited)    r#r(rZRunFinishedErrorrrÚappendr&Zwakeup_thread_and_signal_safe©r rr.rrrrÚ run_sync_soonqs
zEntryQueue.run_sync_soonN)Ú__name__r%Ú __qualname__ÚattrÚibrrÚdictrrr&r(Ú    threadingÚRLockr#r)r*r,r1rrrrr     s            Hr    F)ÚeqÚhashrc@s&eZdZdZe ¡Zddœdd„ZdS)Ú    TrioTokena˜An opaque object representing a single call to :func:`trio.run`.
 
    It has no public constructor; instead, see :func:`current_trio_token`.
 
    This object has two uses:
 
    1. It lets you re-enter the Trio run loop from external threads or signal
       handlers. This is the low-level primitive that :func:`trio.to_thread`
       and `trio.from_thread` use to communicate with worker threads, that
       `trio.open_signal_receiver` uses to receive notifications about
       signals, and so forth.
 
    2. Each call to :func:`trio.run` has exactly one associated
       :class:`TrioToken` object, so you can use it to identify a particular
       call.
 
    Fr-cGs|jj|f|žd|iŽdS)a¹Schedule a call to ``sync_fn(*args)`` to occur in the context of a
        Trio task.
 
        This is safe to call from the main thread, from other threads, and
        from signal handlers. This is the fundamental primitive used to
        re-enter the Trio run loop from outside of it.
 
        The call will happen "soon", but there's no guarantee about exactly
        when, and no mechanism provided for finding out when it's happened.
        If you need this, you'll have to build your own.
 
        The call is effectively run as part of a system task (see
        :func:`~trio.lowlevel.spawn_system_task`). In particular this means
        that:
 
        * :exc:`KeyboardInterrupt` protection is *enabled* by default; if
          you want ``sync_fn`` to be interruptible by control-C, then you
          need to use :func:`~trio.lowlevel.disable_ki_protection`
          explicitly.
 
        * If ``sync_fn`` raises an exception, then it's converted into a
          :exc:`~trio.TrioInternalError` and *all* tasks are cancelled. You
          should be careful that ``sync_fn`` doesn't crash.
 
        All calls with ``idempotent=False`` are processed in strict
        first-in first-out order.
 
        If ``idempotent=True``, then ``sync_fn`` and ``args`` must be
        hashable, and Trio will make a best-effort attempt to discard any
        call submission which is equal to an already-pending call. Trio
        will process these in first-in first-out order.
 
        Any ordering guarantees apply separately to ``idempotent=False``
        and ``idempotent=True`` calls; there's no rule for how calls in the
        different categories are ordered with respect to each other.
 
        :raises trio.RunFinishedError:
              if the associated call to :func:`trio.run`
              has already exited. (Any call that *doesn't* raise this error
              is guaranteed to be fully processed before :func:`trio.run`
              exits.)
 
        r.N)Ú_reentry_queuer1r0rrrr1—s,zTrioToken.run_sync_soonN)r2r%r3Ú__doc__r4r5r<r1rrrrr;sr;)Ú    metaclass) Ú collectionsrr7r4ÚrZ_utilrZ_wakeup_socketpairrÚsr    r;rrrrÚ<module>s    
u