Replies: 3 comments 1 reply
-
This claim is surprising (to me). Stalling is usually a result of calling a blocking function in an asynchronous task - a basic coding error. You might be interested in this threadsafe queue - intended for interfacing asyncio code to hard ISR or threaded code. |
Beta Was this translation helpful? Give feedback.
-
I would very much like to see this as it's not my experience. |
Beta Was this translation helpful? Give feedback.
-
I am very interested in having a system similar to Socket Option 20. s.setsockopt(socket.SOL_SOCKET, 20, handler) Being able to register callbacks for any kind of user-defined event can be very useful. I am very interested to see how you implement your event loop if you have any work in progress. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When implementing event-driven control code that needs to deal with events from interrupt handlers, IO stream and other threads, there is currently no efficient, low latency way for foreground code to watch for both the availability of stream data and events from background sources. The
select
module provides theselect
function andPoll
class that can efficiently idle waiting for stream events, but to also watch other sorts of events the foreground code needs to periodically check. This can either poll rapidly, which doesn't make efficient use of CPU idling functions, or it can poll slowly, which leads to high latency. It would be great to be able to get the best of both worlds.I propose that there be new
Event
andQueue
classes that can be used along side sockets and IO stream inselect
calls andPoll
objects. These would be explicitly safe to call from both hard interrupt contexts and alternate threads on platforms that support them, and would allow a single call to wait for any sort of event.The general semantics for an
Event
would be similar tothreading.Event
class in CPython, with the addition that when it is provided to theselect
function orPoll
class it would show as readable when the event is set and writable when the event is clear. AQueue
would have the conventionalput
andget
calls and would be readable when not empty and writable when not full. Queues would need to be fixed length in order to be used from hard interrupt handlers.It's worth noting that there is an existing
Event
class inasyncio
module that works forasync
code. The Pythonasync
model has its merits but many people find async code hard to debug and in my experience it's prone to stalling on MicroPython, so having a good alternative for synchronous programming would be valuable.The implementation of these classes appears to be pretty simple. One open question is if these should be in a new module or if they should go into the existing
select
module.Suggestions and comments welcomed.
Beta Was this translation helpful? Give feedback.
All reactions