|
109 | 109 | )
|
110 | 110 |
|
111 | 111 |
|
112 |
| -try: |
113 |
| - from gevent.monkey import is_module_patched # type: ignore |
114 |
| -except ImportError: |
115 |
| - |
116 |
| - def is_module_patched(*args, **kwargs): |
117 |
| - # type: (*Any, **Any) -> bool |
118 |
| - # unable to import from gevent means no modules have been patched |
119 |
| - return False |
120 |
| - |
121 |
| - |
122 | 112 | try:
|
123 | 113 | from gevent import get_hub as get_gevent_hub # type: ignore
|
| 114 | + from gevent.monkey import get_original, is_module_patched # type: ignore |
| 115 | + |
| 116 | + thread_sleep = get_original("time", "sleep") |
124 | 117 | except ImportError:
|
125 | 118 |
|
126 | 119 | def get_gevent_hub():
|
127 | 120 | # type: () -> Any
|
128 | 121 | return None
|
129 | 122 |
|
| 123 | + thread_sleep = time.sleep |
| 124 | + |
| 125 | + def is_module_patched(*args, **kwargs): |
| 126 | + # type: (*Any, **Any) -> bool |
| 127 | + # unable to import from gevent means no modules have been patched |
| 128 | + return False |
| 129 | + |
130 | 130 |
|
131 | 131 | def is_gevent():
|
132 | 132 | # type: () -> bool
|
@@ -797,7 +797,7 @@ def run(self):
|
797 | 797 | # not sleep for too long
|
798 | 798 | elapsed = time.perf_counter() - last
|
799 | 799 | if elapsed < self.interval:
|
800 |
| - time.sleep(self.interval - elapsed) |
| 800 | + thread_sleep(self.interval - elapsed) |
801 | 801 |
|
802 | 802 | # after sleeping, make sure to take the current
|
803 | 803 | # timestamp so we can use it next iteration
|
@@ -859,7 +859,7 @@ def run(self):
|
859 | 859 | # not sleep for too long
|
860 | 860 | elapsed = time.perf_counter() - last
|
861 | 861 | if elapsed < self.interval:
|
862 |
| - time.sleep(self.interval - elapsed) |
| 862 | + thread_sleep(self.interval - elapsed) |
863 | 863 |
|
864 | 864 | # after sleeping, make sure to take the current
|
865 | 865 | # timestamp so we can use it next iteration
|
|
0 commit comments