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

fix(profiling): Always use builtin time.sleep #1869

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def is_module_patched(*args, **kwargs):
return False


try:
from gevent.monkey import get_original

thread_sleep = get_original("time", "sleep")
except ImportError:
thread_sleep = time.sleep


_scheduler = None # type: Optional[Scheduler]


Expand Down Expand Up @@ -658,7 +666,7 @@ def run(self):
# not sleep for too long
elapsed = time.perf_counter() - last
if elapsed < self.interval:
time.sleep(self.interval - elapsed)
thread_sleep(self.interval - elapsed)

# after sleeping, make sure to take the current
# timestamp so we can use it next iteration
Expand Down Expand Up @@ -720,7 +728,7 @@ def run(self):
# not sleep for too long
elapsed = time.perf_counter() - last
if elapsed < self.interval:
time.sleep(self.interval - elapsed)
thread_sleep(self.interval - elapsed)

# after sleeping, make sure to take the current
# timestamp so we can use it next iteration
Expand Down