Skip to content

Conversation

@almarklein
Copy link
Member

The asyncadapter is used by loops that are not async by default, like Qt and Wx. This PR adds a get_running_loop() function to that module, so we can integrate better with sniffio. In particular, in wgpu-py I want to be able to do:

module_name  =  sniffio.current_async_library()
mod = sys.modules[module_name]
loop = mod.get_running_loop()
loop.call_soon_async(...)

This code works the same for both asyncio and our adapter. (Trio works differently; we'll handle that with an if statement.)


I explored several options for "integrating" the rendercanvas loop with wgpu-py. My first inclination was to go for something like rendercanvas.get_current_loop(), but it turns out that it's hard to establish when a loop becomes 'active'. E.g. it may already be running in an interactive session. So it felt like it was hard to keep this properly in sync.

The current solution that goes via asyncio, is nice, because you get exactly the loop for the current code invocation, which makes it very robust, even if ppl go do weird things, like running a loop from another loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants