nipo / ausb Goto Github PK
View Code? Open in Web Editor NEWPython Asyncio USB device access
License: Other
Python Asyncio USB device access
License: Other
Is there any way to setup asyncio Reader or Protocol on endpoint?
Context
has no public API for shutting it down and detaching ContextNotifier
from the asyncio loop. This makes working with ausb in projects where the asyncio loop gets replaced repeatedly (e.g. when using pytest-asyncio) quite cumbersome. All references to Context
need to be controlled carefully, using weak references in some places where "hidden" references cannot be avoided (e.g. pytest fixture caching). It also takes quite a lot of additional steps to ensure ContextNotifier._work()
is actually finished (and thus detached from the asyncio loop) before the asyncio loop may be shut down.
On top of that, ausb triggers warnings in usb1:
/usr/lib/python3/dist-packages/usb1/__init__.py:2071: DeprecationWarning: Use "with USBContext() as context:" for safer cleanup on interpreter shutdown. See also USBContext.open().
I have some working PoC code for turning ContextNotifier.close()
into a coroutine (so that it can wait for ContextNotifier._work()
to return), adding a coroutine Context.close()
and having the Context
finalizer use loop.run_until_complete()
(so that existing programs continue to work without explicit close()
). This fixes at least the immediate issue of not being able to explicitly shut down Context
and waiting for it to be detached from the asyncio loop. __aenter__()
/ __aexit__()
would be natural additions on top of that to make it work similar to the recommended way of using usb1.USBContext
.
The usb1 warning can probably be avoided by invoking usb1.USBContext.__enter__()
in Context.__init__()
and usb1.USBContext.__exit__()
in Context.close()
. Haven't tried that out yet.
Before cleaning up my PoC and sending a PR I'd like to make sure we agree on the approach.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.