-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5044 - Fix successive AsyncMongoClients on a single loop always ti… #2065
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
Changes from 4 commits
5a1e7cb
cdc2cf0
b898826
6547c3c
f1f8d62
a4eedb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,17 +75,12 @@ def close(self, dummy: Any = None) -> None: | |
| callback; see monitor.py. | ||
| """ | ||
| self._stopped = True | ||
| if self._task is not None: | ||
| self._task.cancel() | ||
|
||
|
|
||
| async def join(self, timeout: Optional[int] = None) -> None: | ||
| if self._task is not None: | ||
| try: | ||
| await asyncio.wait_for(self._task, timeout=timeout) # type-ignore: [arg-type] | ||
| except asyncio.TimeoutError: | ||
| # Task timed out | ||
| pass | ||
| except asyncio.exceptions.CancelledError: | ||
| # Task was already finished, or not yet started. | ||
| raise | ||
| await asyncio.wait([self._task], timeout=timeout) # type-ignore: [arg-type] | ||
|
|
||
| def wake(self) -> None: | ||
| """Execute the target function soon.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can call join here because there are cases where close() gets called by the monitor thread/task itself. Joining on yourself will cause the thread/task to hang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we remove these changes an open a new issue to track improving the cleanup behavior? Then this PR can be focused on just the network_layer changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not invest time in fixing the cleanup behavior for a test suite we're already working on refactoring. If we're fine with the tests throwing some warnings during the conversion to pytest I'd prefer to just let them throw.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand your comment. Don't we eventually need client.close() to await all the background tasks? That's what I think we need a new ticket to track. This isn't really a test suite issue, it's something end users will encounter when closing clients too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more referring to the work required to get the correct cleanup behavior functioning in our existing test suite. We already have quite a few workarounds for the async test suite to work within the current structure. I expect fixing this issue will only add onto that burden at the same time we're also refactoring the suite entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the core issue of
AsyncMongoClient.close()not awaiting all its background tasks needs to be addressed. I'm worried that in doing so with our current test suite, we'll be doing significant additional work that will be thrown out as part of the pytest refactor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. Yes I agree with you on the unittest specific changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open a separate ticket for the
AsyncMongoClient.close()changes, but we'll need to decide what to do if the unittest suite doesn't work with them.