zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
80
81
82
83
84
85
86
87
88
89
90
91
U
Z±dõ ã@snddlZddlmZddlmZddlmZejdddGdd    „d    ƒƒZejd
d
dd Gd d „d edƒZ    dS)éN)Ú OrderedDicté)Ú_core)ÚFinalT)ÚfrozenÚslotsc@seZdZe ¡ZdS)Ú_ParkingLotStatisticsN)Ú__name__Ú
__module__Ú __qualname__ÚattrÚibÚ tasks_waiting©rrúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_core/_parking_lot.pyrPsrF)ÚeqÚhashrc@s„eZdZdZejeddZdd„Zdd„Z    e
j dd    „ƒZ d
d „Z e
j d d œdd„ƒZdd„Ze
j d d œdd„ƒZdd„Zdd„ZdS)Ú
ParkingLota¥A fair wait queue with cancellation and requeueing.
 
    This class encapsulates the tricky parts of implementing a wait
    queue. It's useful for implementing higher-level synchronization
    primitives like queues and locks.
 
    In addition to the methods below, you can use ``len(parking_lot)`` to get
    the number of parked tasks, and ``if parking_lot: ...`` to check whether
    there are any parked tasks.
 
    F)ÚfactoryÚinitcCs
t|jƒS)z#Returns the number of parked tasks.)ÚlenÚ_parked©ÚselfrrrÚ__len__gszParkingLot.__len__cCs
t|jƒS)z0True if there are parked tasks, False otherwise.)ÚboolrrrrrÚ__bool__kszParkingLot.__bool__cƒs8t ¡‰d|jˆ<|ˆ_‡fdd„}t |¡IdHdS)zfPark the current task until woken by a call to :meth:`unpark` or
        :meth:`unpark_all`.
 
        Ncsˆjjˆ=tjjS)N)Úcustom_sleep_datarrZAbortZ    SUCCEEDED)Ú_©ÚtaskrrÚabort_fn}s
z!ParkingLot.park.<locals>.abort_fn)rZ current_taskrrZwait_task_rescheduled)rr!rrrÚparkss
 
 zParkingLot.parkccs6tt|t|jƒƒƒD]}|jjdd\}}|VqdS)NF)Úlast)ÚrangeÚminrrÚpopitem)rÚcountrr rrrÚ _pop_severalƒszParkingLot._pop_severalé©r'cCs&t| |¡ƒ}|D]}t |¡q|S)a7Unpark one or more tasks.
 
        This wakes up ``count`` tasks that are blocked in :meth:`park`. If
        there are fewer than ``count`` tasks parked, then wakes as many tasks
        are available and then returns successfully.
 
        Args:
          count (int): the number of tasks to unpark.
 
        )Úlistr(rZ
reschedule)rr'Ztasksr rrrÚunparkˆs  zParkingLot.unparkcCs|jt|ƒdS)zUnpark all parked tasks.r*)r,rrrrrÚ
unpark_all™szParkingLot.unpark_allcCs6t|tƒstdƒ‚| |¡D]}d|j|<||_qdS)a¿Move parked tasks from one :class:`ParkingLot` object to another.
 
        This dequeues ``count`` tasks from one lot, and requeues them on
        another, preserving order. For example::
 
           async def parker(lot):
               print("sleeping")
               await lot.park()
               print("woken")
 
           async def main():
               lot1 = trio.lowlevel.ParkingLot()
               lot2 = trio.lowlevel.ParkingLot()
               async with trio.open_nursery() as nursery:
                   nursery.start_soon(parker, lot1)
                   await trio.testing.wait_all_tasks_blocked()
                   assert len(lot1) == 1
                   assert len(lot2) == 0
                   lot1.repark(lot2)
                   assert len(lot1) == 0
                   assert len(lot2) == 1
                   # This wakes up the task that was originally parked in lot1
                   lot2.unpark()
 
        If there are fewer than ``count`` tasks parked, then reparks as many
        tasks as are available and then returns successfully.
 
        Args:
          new_lot (ParkingLot): the parking lot to move tasks to.
          count (int): the number of tasks to move.
 
        znew_lot must be a ParkingLotN)Ú
isinstancerÚ    TypeErrorr(rr)rÚnew_lotr'r rrrÚreparks
"
 
zParkingLot.reparkcCs|j|t|ƒdS)z€Move all parked tasks from one :class:`ParkingLot` object to
        another.
 
        See :meth:`repark` for details.
 
        r*)r1r)rr0rrrÚ
repark_allÅszParkingLot.repark_allcCstt|jƒdS)zØReturn an object containing debugging information.
 
        Currently the following fields are defined:
 
        * ``tasks_waiting``: The number of tasks blocked on this lot's
          :meth:`park` method.
 
        )r)rrrrrrrÚ
statisticsÎs    zParkingLot.statisticsN)r    r
r Ú__doc__r r rrrrrZenable_ki_protectionr"r(r,r-r1r2r3rrrrrUs
'    r)Ú    metaclass)
r Ú collectionsrÚrZ_utilrÚsrrrrrrÚ<module>Is