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

Prevent MockClock from mutating the current runner #3205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

A5rocks
Copy link
Contributor

@A5rocks A5rocks commented Feb 10, 2025

Based on the issue @jc211 had on Gitter. You probably shouldn't be creating a MockClock and not using it, but this is a footgun.

@A5rocks
Copy link
Contributor Author

A5rocks commented Feb 11, 2025

I thought we were over dtls's smoke test timing out the macos pypy runner! For now I'll just rerun CI.

@@ -119,7 +119,8 @@ def _try_resync_autojump_threshold(self) -> None:
except AttributeError:
pass
else:
runner.clock_autojump_threshold = self._autojump_threshold
if runner.clock is self:
runner.clock_autojump_threshold = self._autojump_threshold
Copy link
Member

@mikenerone mikenerone Feb 11, 2025

Choose a reason for hiding this comment

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

I'm wondering why we even need this attribute on the runner. I only see it referenced in two spots in src/trio/_core/_run.py, which could as easily be changed to runner.clock.autojump_threshold, no? I suspect I'm missing something related to an edge case when the threshold value is changed.

Copy link
Contributor Author

@A5rocks A5rocks Feb 11, 2025

Choose a reason for hiding this comment

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

Because runner.clock isn't necessarily a MockClock which is the only kind with autojump_threshold. Of course it may be possible to getattr(runner.clock, "autojump_threshold", math.inf). Maybe that's a better solution?

On the other hand that means a user-provided clock can't have an attribute named autojump_threshold. So it's limiting but probably not in a way that matters to anyone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better continue with an attribute on runner. It doesn't have any disadvantages in practice (now that this is solved) and allows user clocks not to worry about accidentally overriding some undocumented attribute.

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.

2 participants