Skip to content

PYTHON-4864 - Create async version of SpecRunnerThread #2094

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

Merged
merged 9 commits into from
Feb 4, 2025

Conversation

NoahStapp
Copy link
Contributor

No description provided.

Copy link
Contributor

@sleepyStick sleepyStick Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not loving the duplicated code between sync and async but i'm guessing its because the async version needs some more methods? If so, then i understand and can live with it >.<

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The async version doesn't implement threading.Thread, but it still needs to match the same API as the synchronous version. Let me see if I can reduce some of the duplication though.

Copy link
Contributor Author

@NoahStapp NoahStapp Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some refactoring, much less duplication now. Great call-out!

@NoahStapp NoahStapp requested a review from sleepyStick January 29, 2025 21:58
sleepyStick
sleepyStick previously approved these changes Jan 30, 2025
Copy link
Contributor

@sleepyStick sleepyStick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work!

if _IS_SYNC:
await self.cond.wait(10) # type: ignore[call-arg]
else:
await asyncio.wait_for(self.cond.wait(), timeout=10) # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use our _async_cond_wait compat function here to avoid the branching.

"""Run the 'runOnThread' operation."""
thread = self.entity_map[spec["thread"]]
thread.schedule(lambda: self.run_entity_operation(spec["operation"]))
await thread.schedule(functools.partial(self.run_entity_operation, spec["operation"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we running any async unified tests that use runOnThread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDAM unified tests are the only ones that use runOnThread. Those are currently slated to be converted to async, yes.

@NoahStapp NoahStapp requested a review from ShaneHarvey January 31, 2025 18:18
def __init__(self, name):
super().__init__()

class ConcurrentRunner(PARENT):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to utils.py since it will be used by non-spec tests.

Copy link
Contributor Author

@NoahStapp NoahStapp Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since utils.py is not currently synchro'd, let's delay that move to PYTHON-5113, it'll involve a lot of git changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay then what about helpers.py?

self.name = name
self.stopped = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopped is never set to True by this class.

@NoahStapp NoahStapp requested a review from ShaneHarvey February 3, 2025 20:54
@NoahStapp NoahStapp merged commit b47143c into mongodb:master Feb 4, 2025
36 of 46 checks passed
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.

3 participants