zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
U
Z±dã@s\ddlZddlmZddlmZddlmZejddGdd    „d    ƒƒZGd
d „d ed Z    dS) éNé)Ú_core)Ú
deprecated)ÚFinalT)Úfrozenc@seZdZe ¡Ze ¡ZdS)Ú_UnboundedQueueStatsN)Ú__name__Ú
__module__Ú __qualname__ÚattrÚibÚqsizeÚ tasks_waiting©rrúRd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_core/_unbounded_queue.pyrsrc@s~eZdZdZeddddddd„ƒZd    d
„Zd d „Zd d„Ze    j
dd„ƒZ dd„Z dd„Z dd„Zdd„Zdd„Zdd„ZdS)ÚUnboundedQueuea™An unbounded queue suitable for certain unusual forms of inter-task
    communication.
 
    This class is designed for use as a queue in cases where the producer for
    some reason cannot be subjected to back-pressure, i.e., :meth:`put_nowait`
    has to always succeed. In order to prevent the queue backlog from actually
    growing without bound, the consumer API is modified to dequeue items in
    "batches". If a consumer task processes each batch without yielding, then
    this helps achieve (but does not guarantee) an effective bound on the
    queue's memory use, at the cost of potentially increasing system latencies
    in general. You should generally prefer to use a memory channel
    instead if you can.
 
    Currently each batch completely empties the queue, but `this may change in
    the future <https://github.com/python-trio/trio/issues/51>`__.
 
    A :class:`UnboundedQueue` object can be used as an asynchronous iterator,
    where each iteration returns a new batch of items. I.e., these two loops
    are equivalent::
 
       async for batch in queue:
           ...
 
       while True:
           obj = await queue.get_batch()
           ...
 
    z0.9.0iñztrio.lowlevel.UnboundedQueuez"trio.open_memory_channel(math.inf))ÚissueÚthingZinsteadcCst ¡|_g|_d|_dS©NF)rZ
ParkingLotÚ_lotÚ_dataÚ_can_get©ÚselfrrrÚ__init__,s
zUnboundedQueue.__init__cCsd t|jƒ¡S)Nz!<UnboundedQueue holding {} items>)ÚformatÚlenrrrrrÚ__repr__8szUnboundedQueue.__repr__cCs
t|jƒS)z3Returns the number of items currently in the queue.)rrrrrrr ;szUnboundedQueue.qsizecCs|j S)zÕReturns True if the queue is empty, False otherwise.
 
        There is some subtlety to interpreting this method's return value: see
        `issue #63 <https://github.com/python-trio/trio/issues/63>`__.
 
        )rrrrrÚempty?szUnboundedQueue.emptycCs<|js,|jrt‚|jr&|jjddnd|_|j |¡dS)aPut an object into the queue, without blocking.
 
        This always succeeds, because the queue is unbounded. We don't provide
        a blocking ``put`` method, because it would never need to block.
 
        Args:
          obj (object): The object to enqueue.
 
        é)ÚcountTN)rrÚAssertionErrorrZunparkÚappend)rÚobjrrrÚ
put_nowaitHs 
zUnboundedQueue.put_nowaitcCs|j ¡}|j ¡d|_|Sr)rÚcopyÚclearr)rÚdatarrrÚ_get_batch_protected[s
 
z#UnboundedQueue._get_batch_protectedcCs|js tj‚| ¡S)abAttempt to get the next batch from the queue, without blocking.
 
        Returns:
          list: A list of dequeued items, in order. On a successful call this
              list is always non-empty; if it would be empty we raise
              :exc:`~trio.WouldBlock` instead.
 
        Raises:
          ~trio.WouldBlock: if the queue is empty.
 
        )rrZ
WouldBlockr(rrrrÚget_batch_nowaitas zUnboundedQueue.get_batch_nowaitcÃsNt ¡IdH|js,|j ¡IdH| ¡Sz | ¡W¢St ¡IdHXdS)z¶Get the next batch from the queue, blocking as necessary.
 
        Returns:
          list: A list of dequeued items, in order. This list is always
              non-empty.
 
        N)rZcheckpoint_if_cancelledrrZparkr(Zcancel_shielded_checkpointrrrrÚ    get_batchqs zUnboundedQueue.get_batchcCstt|jƒ|j ¡jdS)a Return an object containing debugging information.
 
        Currently the following fields are defined:
 
        * ``qsize``: The number of items currently in the queue.
        * ``tasks_waiting``: The number of tasks blocked on this queue's
          :meth:`get_batch` method.
 
        )r r)rrrrÚ
statisticsrrrrrr+ƒs
 
ÿzUnboundedQueue.statisticscCs|S©NrrrrrÚ    __aiter__‘szUnboundedQueue.__aiter__cÃs| ¡IdHSr,)r*rrrrÚ    __anext__”szUnboundedQueue.__anext__N)rr    r
Ú__doc__rrrr rrZenable_ki_protectionr$r(r)r*r+r-r.rrrrrs&ü
    
r)Ú    metaclass)
r ÚrZ
_deprecaterZ_utilrÚsrrrrrrÚ<module>s