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 all 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
24 changes: 12 additions & 12 deletions sentry_sdk/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,24 @@
)


try:
from gevent.monkey import is_module_patched # type: ignore
except ImportError:

def is_module_patched(*args, **kwargs):
# type: (*Any, **Any) -> bool
# unable to import from gevent means no modules have been patched
return False


try:
from gevent import get_hub as get_gevent_hub # type: ignore
from gevent.monkey import get_original, is_module_patched # type: ignore

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

def get_gevent_hub():
# type: () -> Any
return None

thread_sleep = time.sleep

def is_module_patched(*args, **kwargs):
# type: (*Any, **Any) -> bool
# unable to import from gevent means no modules have been patched
return False


def is_gevent():
# type: () -> bool
Expand Down Expand Up @@ -797,7 +797,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 @@ -859,7 +859,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