GithubHelp home page GithubHelp logo

ausb's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ausb's Issues

Context lifetime bound to garbage collection

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.