Ai
25 Star 1 Fork 14

src-openEuler/python2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
00181-allow-arbitrary-timeout-in-condition-wait.patch 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
dogsheng 提交于 2019-12-13 16:01 +08:00 . Package init
diff --git a/Lib/threading.py b/Lib/threading.py
index cb49c4a..c9795a5 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -305,7 +305,7 @@ class _Condition(_Verbose):
else:
return True
- def wait(self, timeout=None):
+ def wait(self, timeout=None, balancing=True):
"""Wait until notified or until a timeout occurs.
If the calling thread has not acquired the lock when this method is
@@ -354,7 +354,10 @@ class _Condition(_Verbose):
remaining = endtime - _time()
if remaining <= 0:
break
- delay = min(delay * 2, remaining, .05)
+ if balancing:
+ delay = min(delay * 2, remaining, 0.05)
+ else:
+ delay = remaining
_sleep(delay)
if not gotit:
if __debug__:
@@ -599,7 +602,7 @@ class _Event(_Verbose):
with self.__cond:
self.__flag = False
- def wait(self, timeout=None):
+ def wait(self, timeout=None, balancing=True):
"""Block until the internal flag is true.
If the internal flag is true on entry, return immediately. Otherwise,
@@ -617,7 +620,7 @@ class _Event(_Verbose):
"""
with self.__cond:
if not self.__flag:
- self.__cond.wait(timeout)
+ self.__cond.wait(timeout, balancing)
return self.__flag
# Helper to generate new thread names
@@ -908,7 +911,7 @@ class Thread(_Verbose):
if 'dummy_threading' not in _sys.modules:
raise
- def join(self, timeout=None):
+ def join(self, timeout=None, balancing=True):
"""Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is
@@ -957,7 +960,7 @@ class Thread(_Verbose):
if __debug__:
self._note("%s.join(): timed out", self)
break
- self.__block.wait(delay)
+ self.__block.wait(delay, balancing)
else:
if __debug__:
self._note("%s.join(): thread stopped", self)
@@ -1143,7 +1146,7 @@ class _DummyThread(Thread):
def _set_daemon(self):
return True
- def join(self, timeout=None):
+ def join(self, timeout=None, balancing=True):
assert False, "cannot join a dummy thread"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/python2.git
git@gitee.com:src-openeuler/python2.git
src-openeuler
python2
python2
master

搜索帮助