Fixed cleanup not occuring if KI occurs during wait #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supersedes #16 – credit @aburgm for spotting the underlying error! In this PR I've kept @aburgm's test to validate the fix I've applied.
waits, thunks, loops
@aburgm, you were asking about why we had
waitwrapped into a thunk, rather than being called directly. The reason for this istinyio.to_{asyncio,trio}. The use-case here is when someone has written a tinyio coroutine, but the available event loop is from asyncio/trio. In this case what we need to do is spin up a tinyio loop, but tie its stepping to that of the host event loop – i.e. we want to write an asyncio/trio coroutine which steps the tinyio loop at each await point.If the tinyio loop finds itself sat waiting, then we need to be able to simultaneously (a) wake the tinyio loop back up once the event triggers, but also (b) allow the host event loop to keep stepping in the mean time. To do this, we move the tinyio event-watching to a thread so that we can do both things simultaneously. In order to perform just the event watching in the thread, we need to wrap that operation in a thunk we can schedule on a thread.
other
This PR also swaps out
threading.Eventfor a cross-process compatible choice. Right now this should be invisible to users, but in the future it should enable us to asynchronously launch subprocesses too.