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
U
Z±dOã@sfddlZddlmZddlmZddlZddlmZmZm    Z    edd„ƒZ
Gdd    „d    ƒZ ed
d „ƒZ dS) éN)Úcontextmanager)Ú OrderedDicté)Ú signal_raiseÚis_main_threadÚConflictDetectorc csRi}z(t|ƒD]}t ||¡||<qdVW5| ¡D]\}}t ||¡q6XdS©N)ÚitemsÚsignalÚset)ÚsignalsÚhandlerZoriginal_handlersÚsignumÚoriginal_handler©rúDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_signals.pyÚ_signal_handler,s 
rc@s<eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd S)ÚSignalReceivercCs(tƒ|_tj ¡|_tdƒ|_d|_dS)Nz8only one task can iterate on a signal receiver at a timeF)    rÚ_pendingÚtrioÚlowlevelZ
ParkingLotÚ_lotrÚ_conflict_detectorÚ_closed©ÚselfrrrÚ__init__9s  ÿzSignalReceiver.__init__cCs(|jrt|ƒnd|j|<|j ¡dSr)rrrrZunpark)rrrrrÚ_addBs
 
zSignalReceiver._addcsdˆ_‡‡fdd„‰ˆƒdS)NTcs2ˆjr.ˆjjdd\}}z t|ƒW5ˆƒXdS)NF©Úlast)rÚpopitemr©rÚ_©Ú deliver_nextrrrr$Qs
 z9SignalReceiver._redeliver_remaining.<locals>.deliver_next)rrrr#rÚ_redeliver_remainingIsz#SignalReceiver._redeliver_remainingcCs
t|jƒSr)ÚlenrrrrrÚ_pending_signal_count\sz$SignalReceiver._pending_signal_countcCs|SrrrrrrÚ    __aiter___szSignalReceiver.__aiter__c
Ãsj|jrtdƒ‚|jL|js.|j ¡IdHntj ¡IdH|jj    dd\}}|W5QR£SQRXdS)Nz)open_signal_receiver block already exitedFr)
rÚ RuntimeErrorrrrZparkrrÚ
checkpointr )rrr"rrrÚ    __anext__bszSignalReceiver.__anext__N)    Ú__name__Ú
__module__Ú __qualname__rrr%r'r(r+rrrrr8s     rc    'sh|s tdƒ‚tƒstdƒ‚tj ¡‰tƒ‰‡‡fdd„}z t||ƒ ˆVW5QRXW5ˆ ¡XdS)aÞA context manager for catching signals.
 
    Entering this context manager starts listening for the given signals and
    returns an async iterator; exiting the context manager stops listening.
 
    The async iterator blocks until a signal arrives, and then yields it.
 
    Note that if you leave the ``with`` block while the iterator has
    unextracted signals still pending inside it, then they will be
    re-delivered using Python's regular signal handling logic. This avoids a
    race condition when signals arrives just before we exit the ``with``
    block.
 
    Args:
      signals: the signals to listen for.
 
    Raises:
      TypeError: if no signals were provided.
 
      RuntimeError: if you try to use this anywhere except Python's main
          thread. (This is a Python limitation.)
 
    Example:
 
      A common convention for Unix daemons is that they should reload their
      configuration when they receive a ``SIGHUP``. Here's a sketch of what
      that might look like using :func:`open_signal_receiver`::
 
         with trio.open_signal_receiver(signal.SIGHUP) as signal_aiter:
             async for signum in signal_aiter:
                 assert signum == signal.SIGHUP
                 reload_configuration()
 
    zNo signals were providedz]Sorry, open_signal_receiver is only possible when running in Python interpreter's main threadcsˆjˆj|dddS)NT)Z
idempotent)Z run_sync_soonrr!©ÚqueueÚtokenrrr  sz%open_signal_receiver.<locals>.handlerN)    Ú    TypeErrorrr)rrZcurrent_trio_tokenrr%r)r r rr/rÚopen_signal_receiverqs$ÿ
 r3) r
Ú
contextlibrÚ collectionsrrZ_utilrrrrrr3rrrrÚ<module>s  &
9