-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from wlatanowicz/wl/asyncio
asyncio
- Loading branch information
Showing
70 changed files
with
1,132 additions
and
848 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Changelog | ||
|
||
## 0.4.0 | ||
|
||
Goodbye threads. Welcome async. | ||
|
||
### Features | ||
|
||
* Dropped internal threads in favor of async coroutines. | ||
* Event callback functions can be declared as either normal function or coroutine functions | ||
|
||
|
||
### Breaking changes | ||
|
||
* Removed `non_blocking` decorator. | ||
* Both server and client entrypoint are coroutines now. The have to be run in asyncio loop ie. with `asyncio.run()`. | ||
|
||
### Fixes | ||
|
||
* Fixed a lot of type annotations | ||
* Fixes in logging | ||
|
||
## 0.3.0 | ||
|
||
Enables device cooperation while running in the same INDI server environment. | ||
|
||
### Features | ||
|
||
* Support for pings. | ||
* Support for device snooping. | ||
|
||
### Fixes | ||
|
||
* Ignore GetProperties message with unknown device name. | ||
* Fix formatting of xml messages (added declaration and trailing NL). |
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
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,24 +1,61 @@ | ||
import os | ||
import asyncio | ||
from logging import config | ||
|
||
from indi.client import elements | ||
from indi.client.client import Client | ||
from indi.message import const | ||
from indi.transport.client import TCP | ||
|
||
|
||
host = os.environ.get("INDISERVER_HOST", "indiserver") | ||
port = int(os.environ.get("INDISERVER_PORT", 7624)) | ||
|
||
control_connection = TCP(host, port) | ||
blob_connection = TCP(host, port) | ||
|
||
def client_callback(event): | ||
print(event) | ||
|
||
|
||
client = Client(control_connection, blob_connection) | ||
client.onevent(callback=client_callback) | ||
client.start() | ||
|
||
while True: | ||
pass | ||
def configure_logging(): | ||
config.dictConfig( | ||
{ | ||
"version": 1, | ||
"disable_existing_loggers": False, | ||
"formatters": { | ||
"verbose": { | ||
"format": "[%(asctime)s] %(levelname)s:%(name)s: %(message)s" | ||
}, | ||
}, | ||
"handlers": { | ||
"console": { | ||
"level": os.environ.get("LOG_LEVEL", "INFO"), | ||
"class": "logging.StreamHandler", | ||
"formatter": "verbose", | ||
}, | ||
}, | ||
"loggers": { | ||
"": { | ||
"level": "DEBUG", | ||
"handlers": [ | ||
"console", | ||
], | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
|
||
async def main_loop(): | ||
host = os.environ.get("INDISERVER_HOST", "indiserver") | ||
port = int(os.environ.get("INDISERVER_PORT", 7624)) | ||
|
||
control_connection = TCP(host, port) | ||
blob_connection = TCP(host, port) | ||
|
||
def client_callback(event): | ||
print(event) | ||
|
||
client = Client(control_connection, blob_connection) | ||
client.onevent(callback=client_callback) | ||
|
||
await client.start() | ||
|
||
while True: | ||
await asyncio.sleep(100) | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_logging() | ||
asyncio.run(main_loop()) |
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
Oops, something went wrong.