queutils 0.9.1__py3-none-any.whl → 0.9.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- queutils/__init__.py +3 -3
- queutils/{categorycounterqueue.py → eventcounterqueue.py} +16 -16
- {queutils-0.9.1.dist-info → queutils-0.9.4.dist-info}/METADATA +20 -9
- {queutils-0.9.1.dist-info → queutils-0.9.4.dist-info}/RECORD +6 -6
- {queutils-0.9.1.dist-info → queutils-0.9.4.dist-info}/WHEEL +0 -0
- {queutils-0.9.1.dist-info → queutils-0.9.4.dist-info}/licenses/LICENSE +0 -0
queutils/__init__.py
CHANGED
@@ -2,15 +2,15 @@ from .countable import Countable as Countable
|
|
2
2
|
from .asyncqueue import AsyncQueue as AsyncQueue
|
3
3
|
from .iterablequeue import IterableQueue as IterableQueue, QueueDone as QueueDone
|
4
4
|
from .filequeue import FileQueue as FileQueue
|
5
|
-
from .
|
5
|
+
from .eventcounterqueue import (
|
6
6
|
QCounter as QCounter,
|
7
|
-
|
7
|
+
EventCounterQueue as EventCounterQueue,
|
8
8
|
)
|
9
9
|
|
10
10
|
__all__ = [
|
11
11
|
"asyncqueue",
|
12
12
|
"countable",
|
13
|
-
"
|
13
|
+
"eventcounterqueue",
|
14
14
|
"filequeue",
|
15
15
|
"iterablequeue",
|
16
16
|
]
|
@@ -20,7 +20,7 @@ debug = logger.debug
|
|
20
20
|
T = TypeVar("T")
|
21
21
|
|
22
22
|
|
23
|
-
@deprecated(version="0.9.1", reason="Use
|
23
|
+
@deprecated(version="0.9.1", reason="Use EventCounterQueue instead")
|
24
24
|
class CounterQueue(Queue[T], Countable):
|
25
25
|
"""
|
26
26
|
CounterQueue is a asyncio.Queue for counting items
|
@@ -55,9 +55,9 @@ class CounterQueue(Queue[T], Countable):
|
|
55
55
|
return self._count_items
|
56
56
|
|
57
57
|
|
58
|
-
class
|
58
|
+
class EventCounterQueue(IterableQueue[tuple[str, int]]):
|
59
59
|
"""
|
60
|
-
|
60
|
+
EventCounterQueue is a asyncio.Queue for counting events by name
|
61
61
|
"""
|
62
62
|
|
63
63
|
_counter: defaultdict[str, int]
|
@@ -69,29 +69,29 @@ class CategoryCounterQueue(IterableQueue[tuple[str, int]]):
|
|
69
69
|
self._counter = defaultdict(int)
|
70
70
|
|
71
71
|
async def receive(self) -> tuple[str, int]:
|
72
|
-
"""Receive
|
73
|
-
|
72
|
+
"""Receive an event value from the queue and sum it"""
|
73
|
+
event: str
|
74
74
|
value: int
|
75
|
-
|
76
|
-
self._counter[
|
75
|
+
event, value = await super().get()
|
76
|
+
self._counter[event] += value
|
77
77
|
super().task_done()
|
78
|
-
return (
|
78
|
+
return (event, value)
|
79
79
|
|
80
|
-
async def send(self,
|
81
|
-
"""Send count of
|
82
|
-
await super().put((
|
80
|
+
async def send(self, event: str = "count", value: int = 1) -> None:
|
81
|
+
"""Send count of an event"""
|
82
|
+
await super().put((event, value))
|
83
83
|
return None
|
84
84
|
|
85
|
-
def get_count(self,
|
86
|
-
"""Return count
|
87
|
-
return self._counter[
|
85
|
+
def get_count(self, event: str = "count") -> int:
|
86
|
+
"""Return count for an event"""
|
87
|
+
return self._counter[event]
|
88
88
|
|
89
89
|
def get_counts(self) -> defaultdict[str, int]:
|
90
|
-
"""Return counts of all
|
90
|
+
"""Return counts of all events"""
|
91
91
|
return self._counter
|
92
92
|
|
93
93
|
async def listen(self) -> defaultdict[str, int]:
|
94
|
-
"""Listen for
|
94
|
+
"""Listen for event values"""
|
95
95
|
try:
|
96
96
|
while True:
|
97
97
|
await self.receive()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: queutils
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.4
|
4
4
|
Summary: Handy Python Queue utilies
|
5
5
|
Project-URL: Homepage, https://github.com/Jylpah/queutils
|
6
6
|
Project-URL: Bug Tracker, https://github.com/Jylpah/queutils/issues
|
@@ -35,15 +35,16 @@ Description-Content-Type: text/markdown
|
|
35
35
|
|
36
36
|
Queutils *[Queue Utils]* is a package of handy Python queue classes:
|
37
37
|
|
38
|
-
- **
|
39
|
-
- **
|
40
|
-
- **
|
38
|
+
- **AsyncQueue** - An `async` wrapper for non-async `queue.Queue`
|
39
|
+
- **IterableQueue** - An `AsyncIterable` queue that terminates when finished
|
40
|
+
- **EventCounterQueue** - An `IterableQueue` for counting events in `async` threads
|
41
|
+
- **FileQueue** - Builds an `IterableQueue[pathlib.Path]` of filenames from files/dirs given as input
|
41
42
|
|
42
43
|
|
43
44
|
# AsyncQueue
|
44
45
|
|
45
|
-
|
46
|
-
an `asyncio.Queue` compatible interface to a (non-async) managed `multiprocessing.Queue` and thus enable `async` code in parent/child processes to communicate over `multiprocessing.Queue` as it were an `asyncio.Queue`.
|
46
|
+
`AsyncQueue` is a async wrapper for non-async `queue.Queue`. It can be used to create
|
47
|
+
an `asyncio.Queue` compatible interface to a (non-async) managed `multiprocessing.Queue` and thus enable `async` code in parent/child processes to communicate over `multiprocessing.Queue` as it were an `asyncio.Queue`. Uses `sleep()` for `get()`/`put()` if the queue is empty/full.
|
47
48
|
|
48
49
|
## Features
|
49
50
|
|
@@ -54,10 +55,10 @@ an `asyncio.Queue` compatible interface to a (non-async) managed `multiprocessin
|
|
54
55
|
|
55
56
|
# IterableQueue
|
56
57
|
|
57
|
-
|
58
|
+
`IterableQueue` is an `asyncio.Queue` subclass that is `AsyncIterable[T]` i.e. it can be
|
58
59
|
iterated in `async for` loop. `IterableQueue` terminates automatically when the queue has been filled and emptied.
|
59
60
|
|
60
|
-
The `IterableQueue` requires "producers" (functions adding items to the queue) to register themselves and it
|
61
|
+
The `IterableQueue` requires "producers" (functions adding items to the queue) to register themselves with `add_producer()` call and it
|
61
62
|
keeps count of registered producers which are "finished" adding items to the queue. Once all the registered
|
62
63
|
producers are "finished", the queue enters into "filled" state and no new items can be added. Once an
|
63
64
|
"filled" queue is emptied, the queue becomes "done" and all new `get()` calls to the queue will
|
@@ -74,9 +75,19 @@ producers are "finished", the queue enters into "filled" state and no new items
|
|
74
75
|
- Countable property can be disabled with count_items=False. This is useful when you
|
75
76
|
want to sum the count of multiple IterableQueues
|
76
77
|
|
78
|
+
# EventCounterQueue
|
79
|
+
|
80
|
+
`EventCounterQueue` can be used to count named events (default event is `count`) between `async` threads. `async` worker threads call `queue.send(event="event_name", N=amount)`. The receving end can either `receive()` a single event or `listen()` all events and return `collections.defaultdict[str, int]` as a result.
|
81
|
+
|
82
|
+
## Features
|
83
|
+
|
84
|
+
- Supports multiple producers and a single listener
|
85
|
+
- Default event is `count`
|
86
|
+
|
87
|
+
|
77
88
|
# FileQueue
|
78
89
|
|
79
|
-
|
90
|
+
`FileQueue` builds a queue (`IterableQueue[pathlib.Path]`) of the matching
|
80
91
|
files found based on search parameters given. It can search both list of files or directories or
|
81
92
|
mixed. Async method `FileQueue.mk_queue()` searches subdirectories of given directories.
|
82
93
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
queutils/__init__.py,sha256=
|
1
|
+
queutils/__init__.py,sha256=rbDSh9513Dday-MfWzPOUfN7Aj2x4IqrvCmKbBj7has,441
|
2
2
|
queutils/asyncqueue.py,sha256=GZRmlWTBQoKzTf7xr4MI-qhNqvIiaNWswAxFokP91Lg,2789
|
3
|
-
queutils/categorycounterqueue.py,sha256=Ku5pAJXSsoNyUsuWkQe9w7SaPeiPwPHFMdZFqA0LtBw,3097
|
4
3
|
queutils/countable.py,sha256=YSi7ILf9CuB5Tm3T4UUMEFlveqzqcmomfqJAlLGHEz8,172
|
4
|
+
queutils/eventcounterqueue.py,sha256=NjT8FqEskZhjmus7L333DZU9kXoZCNsn7ydCI5HSe1U,3047
|
5
5
|
queutils/filequeue.py,sha256=q2ly9H-lSCq6xuOqT1IlWgyCVyLoZiKbc0NuzmkF4aw,5360
|
6
6
|
queutils/iterablequeue.py,sha256=ZXwa9040yTawL1DMMNBXgQKiYr32nmzuSbgi-raAtZc,8664
|
7
7
|
queutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
queutils-0.9.
|
9
|
-
queutils-0.9.
|
10
|
-
queutils-0.9.
|
11
|
-
queutils-0.9.
|
8
|
+
queutils-0.9.4.dist-info/METADATA,sha256=v3MC3cKun7jnGfnR9WFs7PYQHiCEDu398YBBVEWVcqE,4768
|
9
|
+
queutils-0.9.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
queutils-0.9.4.dist-info/licenses/LICENSE,sha256=J1zeIKU2JVQmhwO2hHQDK8WR6zjVZ-wX8r7ZlL45AbI,1063
|
11
|
+
queutils-0.9.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|