New submission from SD <[email protected]>:
The overhead in Python 3 for threading.Event().wait() is much larger than
Python 2. I am trying to run a script at 60hz which worked correctly in Python2
but does not in Python 3. Here is a minimal example to demonstrate:
#!/usr/bin/env python
import threading
import time
def sample_thread(stop_ev):
while not stop_ev.is_set():
t2 = time.time()
stop_ev.wait(0.016999959945)
print((time.time() - t2))
def main():
stop_ev = threading.Event()
sample_t = threading.Thread(target=sample_thread, args=(stop_ev, ))
sample_t.start()
# Other stuff here, sleep is just dummy
time.sleep(14)
stop_ev.set()
print('End reached.')
if __name__ == '__main__':
main()
Python 2.7.0 consistently prints :
0.0169999599457
0.0169999599457
0.0170001983643
0.0169999599457
0.0169999599457
0.0169999599457
0.0169999599457
0.0169999599457
Python 3.8.2 waits much longer
0.031026363372802734
0.0320279598236084
0.031026363372802734
0.031026840209960938
0.031527042388916016
0.031026601791381836
0.03103041648864746
0.03302431106567383
----------
messages: 373660
nosy: SD
priority: normal
severity: normal
status: open
title: Python3 threading.Event().wait time is twice as large as Python27
type: performance
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41299>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com