-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and fix asyncio warnings in core and example
- Loading branch information
Showing
4 changed files
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from flowbase.flowbase import Process, Network, Port | ||
from flowbase.flowbase import Process, Network, Port, run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
""" | ||
Copyright (c) 2020 Samuel Lampa <[email protected]> | ||
Copyright (c) 2021 Samuel Lampa <[email protected]> | ||
""" | ||
|
||
import asyncio | ||
import typing | ||
|
||
|
||
def run(awaitable, **kwargs): | ||
asyncio.run(awaitable, **kwargs) | ||
|
||
|
||
class Process: | ||
def run(self): | ||
async def run(self): | ||
raise NotImplementedError( | ||
f"str(type(self)) can not be used directly, but must be subclassed" | ||
) | ||
|
||
|
||
class Network(Process): | ||
_processes = {} | ||
_driver_process = None | ||
|
||
def __init__(self): | ||
self._loop = asyncio.get_event_loop() | ||
|
||
def add_process(self, name: str, process: Process): | ||
self._processes[name] = process | ||
self._loop.create_task(process.run()) | ||
self._driver_process = process | ||
asyncio.create_task(process.run()) | ||
|
||
def run(self): | ||
self._loop.run_until_complete(self._driver_process.run()) | ||
async def run(self): | ||
[await p.run() for _, p in self._processes.items()] | ||
|
||
|
||
class Port(asyncio.Queue): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters