Skip to content

Commit b32239c

Browse files
committed
Simplify and fix asyncio warnings in core and example
1 parent 7c58e8c commit b32239c

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

examples/string_processing_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import flowbase
22

33

4-
def main():
4+
async def main():
55
net = flowbase.Network()
66

77
# Initialize components
@@ -32,7 +32,7 @@ def main():
3232
printer.in_lines = stringjoiner.out_lines
3333

3434
# Run the full event loop
35-
net.run()
35+
await net.run()
3636

3737

3838
class HiSayer:
@@ -97,4 +97,4 @@ async def run(self):
9797

9898

9999
if __name__ == "__main__":
100-
main()
100+
flowbase.run(main(), debug=True)

flowbase/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from flowbase.flowbase import Process, Network, Port
1+
from flowbase.flowbase import Process, Network, Port, run

flowbase/flowbase.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
"""
2-
Copyright (c) 2020 Samuel Lampa <[email protected]>
2+
Copyright (c) 2021 Samuel Lampa <[email protected]>
33
"""
44

55
import asyncio
66
import typing
77

88

9+
def run(awaitable, **kwargs):
10+
asyncio.run(awaitable, **kwargs)
11+
12+
913
class Process:
10-
def run(self):
14+
async def run(self):
1115
raise NotImplementedError(
1216
f"str(type(self)) can not be used directly, but must be subclassed"
1317
)
1418

1519

1620
class Network(Process):
1721
_processes = {}
18-
_driver_process = None
19-
20-
def __init__(self):
21-
self._loop = asyncio.get_event_loop()
2222

2323
def add_process(self, name: str, process: Process):
2424
self._processes[name] = process
25-
self._loop.create_task(process.run())
26-
self._driver_process = process
25+
asyncio.create_task(process.run())
2726

28-
def run(self):
29-
self._loop.run_until_complete(self._driver_process.run())
27+
async def run(self):
28+
[await p.run() for _, p in self._processes.items()]
3029

3130

3231
class Port(asyncio.Queue):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name="flowbase",
14-
version="0.0.2",
14+
version="0.0.3",
1515
description="Python implementation of the FlowBase Flow-based Programming micro-framework idea (see flowbase.org)",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)