asimpy 0.4.1__py3-none-any.whl → 0.5.0__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.
- asimpy/environment.py +6 -2
- asimpy/event.py +4 -0
- asimpy/simqueue.py +13 -0
- asimpy/timeout.py +8 -2
- {asimpy-0.4.1.dist-info → asimpy-0.5.0.dist-info}/METADATA +2 -15
- {asimpy-0.4.1.dist-info → asimpy-0.5.0.dist-info}/RECORD +8 -8
- {asimpy-0.4.1.dist-info → asimpy-0.5.0.dist-info}/WHEEL +0 -0
- {asimpy-0.4.1.dist-info → asimpy-0.5.0.dist-info}/licenses/LICENSE.md +0 -0
asimpy/environment.py
CHANGED
|
@@ -5,10 +5,13 @@ import heapq
|
|
|
5
5
|
import itertools
|
|
6
6
|
from typing import Callable
|
|
7
7
|
|
|
8
|
+
from .event import NO_TIME
|
|
8
9
|
from .timeout import Timeout
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class Environment:
|
|
13
|
+
"""Simulation environment."""
|
|
14
|
+
|
|
12
15
|
def __init__(self, logging=False):
|
|
13
16
|
self._now = 0
|
|
14
17
|
self._logging = logging
|
|
@@ -29,8 +32,9 @@ class Environment:
|
|
|
29
32
|
pending = heapq.heappop(self._pending)
|
|
30
33
|
if until is not None and pending.time > until:
|
|
31
34
|
break
|
|
32
|
-
|
|
33
|
-
pending.
|
|
35
|
+
result = pending.callback()
|
|
36
|
+
if (result is not NO_TIME) and (pending.time > self._now):
|
|
37
|
+
self._now = pending.time
|
|
34
38
|
|
|
35
39
|
def _immediate(self, callback):
|
|
36
40
|
self.schedule(self._now, callback)
|
asimpy/event.py
CHANGED
asimpy/simqueue.py
CHANGED
|
@@ -52,6 +52,19 @@ class Queue:
|
|
|
52
52
|
class PriorityQueue(Queue):
|
|
53
53
|
"""Ordered queue."""
|
|
54
54
|
|
|
55
|
+
async def get(self):
|
|
56
|
+
"""Get highest priority item from the queue."""
|
|
57
|
+
if self._items:
|
|
58
|
+
item = heapq.heappop(self._items)
|
|
59
|
+
evt = Event(self._env)
|
|
60
|
+
self._env._immediate(lambda: evt.succeed(item))
|
|
61
|
+
evt._on_cancel = lambda: heapq.heappush(self._items, item)
|
|
62
|
+
return await evt
|
|
63
|
+
|
|
64
|
+
evt = Event(self._env)
|
|
65
|
+
self._getters.append(evt)
|
|
66
|
+
return await evt
|
|
67
|
+
|
|
55
68
|
async def put(self, item: Any):
|
|
56
69
|
"""
|
|
57
70
|
Add one item to the queue.
|
asimpy/timeout.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Wait for a simulated time to pass."""
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING
|
|
4
|
-
from .event import Event
|
|
4
|
+
from .event import NO_TIME, Event
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
7
|
from .environment import Environment
|
|
@@ -20,4 +20,10 @@ class Timeout(Event):
|
|
|
20
20
|
"""
|
|
21
21
|
assert delay >= 0
|
|
22
22
|
super().__init__(env)
|
|
23
|
-
env.schedule(env.now + delay,
|
|
23
|
+
env.schedule(env.now + delay, self._fire)
|
|
24
|
+
|
|
25
|
+
def _fire(self):
|
|
26
|
+
"""Handle cancellation case."""
|
|
27
|
+
if self._cancelled:
|
|
28
|
+
return NO_TIME
|
|
29
|
+
self.succeed()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: asimpy
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A simple discrete event simulator using async/await
|
|
5
5
|
Author-email: Greg Wilson <gvwilson@third-bit.com>
|
|
6
6
|
Maintainer-email: Greg Wilson <gvwilson@third-bit.com>
|
|
@@ -10,17 +10,6 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.12
|
|
13
|
-
Provides-Extra: dev
|
|
14
|
-
Requires-Dist: build>=1.4.0; extra == 'dev'
|
|
15
|
-
Requires-Dist: markdown-include>=0.8.1; extra == 'dev'
|
|
16
|
-
Requires-Dist: mkdocs-awesome-pages-plugin>=2.10.1; extra == 'dev'
|
|
17
|
-
Requires-Dist: mkdocs-material>=9.7.1; extra == 'dev'
|
|
18
|
-
Requires-Dist: mkdocs>=1.6.1; extra == 'dev'
|
|
19
|
-
Requires-Dist: mkdocstrings[python]>=1.0.0; extra == 'dev'
|
|
20
|
-
Requires-Dist: ruff>=0.14.10; extra == 'dev'
|
|
21
|
-
Requires-Dist: taskipy>=1.14.1; extra == 'dev'
|
|
22
|
-
Requires-Dist: twine>=6.2.0; extra == 'dev'
|
|
23
|
-
Requires-Dist: ty>=0.0.11; extra == 'dev'
|
|
24
13
|
Description-Content-Type: text/markdown
|
|
25
14
|
|
|
26
15
|
# asimpy
|
|
@@ -30,7 +19,6 @@ A simple discrete event simulation framework in Python using `async`/`await`.
|
|
|
30
19
|
- [Documentation][docs]
|
|
31
20
|
- [Package][package]
|
|
32
21
|
- [Repository][repo]
|
|
33
|
-
- [Examples][examples]
|
|
34
22
|
|
|
35
23
|
*Thanks to the creators of [SimPy][simpy] for inspiration.*
|
|
36
24
|
|
|
@@ -234,8 +222,7 @@ The sequence of events is:
|
|
|
234
222
|
| FirstOf succeeds with winner | q1=[], q2=["B"] | _value=("a","A"), _triggered=True | Processes waiting on FirstOf resumed | `Tester` receives ("a","A") |
|
|
235
223
|
| `Tester` continues execution | q1=[], q2=["B"] | - | - | Remaining queue items untouched; correct order guaranteed |
|
|
236
224
|
|
|
237
|
-
[docs]: https://
|
|
238
|
-
[examples]: https://gvwilson.github.io/asimpy/examples/
|
|
225
|
+
[docs]: https://asimpy.readthedocs.io/
|
|
239
226
|
[package]: https://pypi.org/project/asimpy/
|
|
240
227
|
[repo]: https://github.com/gvwilson/asimpy
|
|
241
228
|
[simpy]: https://simpy.readthedocs.io/
|
|
@@ -2,15 +2,15 @@ asimpy/__init__.py,sha256=c01u2z29W688jAccd6OKnON132IueBKn31JrcA5wNSk,490
|
|
|
2
2
|
asimpy/_adapt.py,sha256=-rUIvJMneEDdxdiMImwXYfMChsqdQwWoyHVsDCsxRKI,521
|
|
3
3
|
asimpy/allof.py,sha256=artqJqBHUaHh8oOk3a3tpqIlt5sJzGW9VEJ2-YkdECU,1211
|
|
4
4
|
asimpy/barrier.py,sha256=evubm6H_93qi9vBogqrNLg1dZosY7YdnCnJc1jNGYW4,770
|
|
5
|
-
asimpy/environment.py,sha256=
|
|
6
|
-
asimpy/event.py,sha256=
|
|
5
|
+
asimpy/environment.py,sha256=EEHkW6vuQJF9koY_DrNVXQ9bUj4GQDKRWkGCqvDx9U0,1351
|
|
6
|
+
asimpy/event.py,sha256=gS4_PHydP6MUNaEG2o0L8QK67Y1R_9dybJq4BEQXsu8,1437
|
|
7
7
|
asimpy/firstof.py,sha256=htwskm_5lwBVD6yb7hD8jmAypeaJJk5iUqB7cKPYWyk,1356
|
|
8
8
|
asimpy/interrupt.py,sha256=tybPzsCeX7cpVL6psOUQf6egcAujV0vnJe1zDwkZWxo,406
|
|
9
9
|
asimpy/process.py,sha256=IQldzjqF5CuBUccdkM3ZV5mEtEIivZx8whGeNEr2jIc,2349
|
|
10
10
|
asimpy/resource.py,sha256=Ml8E71FdJ61Sy6dcoXyQkb0SXLv6xRBkI7Rkriyu438,1680
|
|
11
|
-
asimpy/simqueue.py,sha256=
|
|
12
|
-
asimpy/timeout.py,sha256=
|
|
13
|
-
asimpy-0.
|
|
14
|
-
asimpy-0.
|
|
15
|
-
asimpy-0.
|
|
16
|
-
asimpy-0.
|
|
11
|
+
asimpy/simqueue.py,sha256=B826YjNKHXkdkRRYPijQETkF9w84hoWNT4an_YQcalw,1953
|
|
12
|
+
asimpy/timeout.py,sha256=75OqbpLeepJ5UdSN6F6JZ0ctlr53jpuilaI7Wxi9XP8,686
|
|
13
|
+
asimpy-0.5.0.dist-info/METADATA,sha256=gsgdx4ouMqpNgHBGLaKfC5ygBWEjNgYlv8IwmCRohKc,8709
|
|
14
|
+
asimpy-0.5.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
15
|
+
asimpy-0.5.0.dist-info/licenses/LICENSE.md,sha256=IjTDUvBk8xdl_n50CG1Vtk4FYdrS-C3uEYrRWAoOQqQ,1066
|
|
16
|
+
asimpy-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|