Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate tnz instances #73

Merged
merged 5 commits into from
Jul 5, 2023
Merged

separate tnz instances #73

merged 5 commits into from
Jul 5, 2023

Conversation

najohnsn
Copy link
Member

@najohnsn najohnsn commented Jun 30, 2023

This PR resolves #71. There are 2 main aspects to this PR:

  • Scope the event used by Tnz.wait() to that Tnz instance, but allow Ati to request the same event be used by multiple instances.
  • Use asyncio.get_event_loop() to choose the loop for each Tnz instance, by default. But allow a user to control the loop that is used to allow multiple threads to work with their own Tnz instances.

These changes required some refactoring. Previously, event handling centered around global variables/functions in tnz.py that were used _sigx.py, _termlib.py, and zti.py. This processing has been simplified and zti.py becomes the central point of control. A new Ati.get_asyncio_event_loop() method is used to get the necessary data for that control. This includes both handling of stdin and signals.

In general, asyncio.get_event_loop() is used to determine the event loop. Although this is not recommended when there is no running event loop (and no event loop has been set), it has historically be used and this is not changed at this time. This allows a user to control the event loop used by setting the event loop - though there are some levels of Python (but not the most recent) that will issue a deprecations warning when asynci.get_event_loop() is used and there is no running event loop - regardless if one has been set or not.

The one exception is when setting the first Ati session. In that case, a new event loop is always created with asyncio.new_event_loop(). The intent is to ensure that the event loop used is never one that is currently running.

The choice of the event loop on Windows has always been more difficult since the default Windows event loop is the ProactorEventLoop - an event loop that does not support add_reader(). But it just so happens that the requirement for another thread to transfer the stdin helps to eliminate the requirement for add_reader(). With this PR, special code to avoid the ProactorEventLoop has been removed and instead, the thread used to transfer stdin will wakeup the event loop instead of add_reader(). Once the use of add_reader() was removed, there was no need for the extra socket for Windows (which had annoying ConnectionResetErrors).

Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
@najohnsn najohnsn force-pushed the noglobal-tnz branch 5 times, most recently from 89718e1 to d34c265 Compare July 3, 2023 20:28
Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
@najohnsn najohnsn marked this pull request as ready for review July 3, 2023 20:32
Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
Signed-off-by: Neil Johnson <najohnsn@us.ibm.com>
@najohnsn najohnsn merged commit 0efccca into main Jul 5, 2023
@najohnsn najohnsn deleted the noglobal-tnz branch July 5, 2023 16:40
@najohnsn najohnsn mentioned this pull request Jul 7, 2023
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.

Only single instance of Tnz feasible
1 participant