[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2020-07-14 Thread SD


New submission from SD :

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.01659945)
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.016599457
0.016599457
0.0170001983643
0.016599457
0.016599457
0.016599457
0.016599457
0.016599457

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 
<https://bugs.python.org/issue41299>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2020-07-15 Thread SD


SD  added the comment:

I have tested this both on vs code terminal and cygwin for windows.

3.8.2 : 

python -m test.pythoninfo
Python debug information


Py_DEBUG: No (sys.gettotalrefcount() missing)
_decimal.__libmpdec_version__: 2.4.2
builtins.float.double_format: IEEE, little-endian
builtins.float.float_format: IEEE, little-endian
datetime.datetime.now: 2020-07-15 09:09:34.936153
expat.EXPAT_VERSION: expat_2.2.8
locale.encoding: cp1252
os.cpu_count: 12
os.environ[APPDATA]: C:\Users\\AppData\Roaming
os.environ[COMPUTERNAME]: 
os.environ[COMSPEC]: C:\Windows\system32\cmd.exe
os.environ[HOMEDRIVE]: C:
os.environ[HOMEPATH]: \Users\
os.environ[LANG]: en_GB.UTF-8
os.environ[PATHEXT]: 
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL
os.environ[PATH]: C:\Program Files\NVIDIA GPU Computing 
Toolkit\CUDA\v9.2\bin;C:\Program Files\NVIDIA GPU Computing 
Toolkit\CUDA\v9.2\libnvvp;C:\Program 
Files\SlikSvn\bin;C:\Python\Python38\Scripts\;C:\Python\Python38\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program
 Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program 
Files\dotnet\;C:\Program Files\TortoiseSVN\bin;C:\Program 
Files\CMake\bin;C:\Program Files (x86)\IncrediBuild;C:\Program Files\NVIDIA 
Corporation\NVIDIA 
NvDLISR;C:\Users\\AppData\Local\Microsoft\WindowsApps;;C:\Users\\AppData\Local\Programs\Microsoft
 VS Code\bin
os.environ[SYSTEMROOT]: C:\Windows
os.environ[TEMP]: C:\Users\\AppData\Local\Temp
os.environ[TMP]: C:\Users\\AppData\Local\Temp
os.environ[USERPROFILE]: C:\Users\
os.environ[WINDIR]: C:\Windows
os.getcwd: 
os.login: 
os.name: nt
os.supports_bytes_environ: False
os.supports_effective_ids: []
os.supports_fd: ['stat', 'truncate']
os.supports_follow_symlinks: ['stat']
os.umask: 000
platform.architecture: 64bit WindowsPE
platform.platform: Windows-10-10.0.18362-SP0
platform.python_implementation: CPython
pymem.allocator: pymalloc
pymem.with_pymalloc: True
socket.hostname: 
sqlite3.sqlite_version: 3.28.0
sqlite3.version: 2.6.0
ssl.HAS_SNI: True
ssl.OPENSSL_VERSION: OpenSSL 1.1.1d  10 Sep 2019
ssl.OPENSSL_VERSION_INFO: (1, 1, 1, 4, 15)
ssl.OP_ALL: -0x7fac
ssl.OP_NO_TLSv1_1: 0x1000
ssl.SSLContext.maximum_version: TLSVersion.MAXIMUM_SUPPORTED
ssl.SSLContext.minimum_version: TLSVersion.MINIMUM_SUPPORTED
ssl.SSLContext.options: 
Options.OP_NO_SSLv3|OP_CIPHER_SERVER_PREFERENCE|OP_ENABLE_MIDDLEBOX_COMPAT|OP_NO_COMPRESSION|OP_ALL
ssl.SSLContext.protocol: _SSLMethod.PROTOCOL_TLS
ssl.SSLContext.verify_mode: VerifyMode.CERT_NONE
ssl.default_https_context.maximum_version: TLSVersion.MAXIMUM_SUPPORTED
ssl.default_https_context.minimum_version: TLSVersion.MINIMUM_SUPPORTED
ssl.default_https_context.options: 
Options.OP_NO_SSLv3|OP_CIPHER_SERVER_PREFERENCE|OP_ENABLE_MIDDLEBOX_COMPAT|OP_NO_COMPRESSION|OP_ALL
ssl.default_https_context.protocol: _SSLMethod.PROTOCOL_TLS
ssl.default_https_context.verify_mode: VerifyMode.CERT_REQUIRED
ssl.stdlib_context.maximum_version: TLSVersion.MAXIMUM_SUPPORTED
ssl.stdlib_context.minimum_version: TLSVersion.MINIMUM_SUPPORTED
ssl.stdlib_context.options: 
Options.OP_NO_SSLv3|OP_CIPHER_SERVER_PREFERENCE|OP_ENABLE_MIDDLEBOX_COMPAT|OP_NO_COMPRESSION|OP_ALL
ssl.stdlib_context.protocol: _SSLMethod.PROTOCOL_TLS
ssl.stdlib_context.verify_mode: VerifyMode.CERT_NONE
subprocess._USE_POSIX_SPAWN: False
sys.api_version: 1013
sys.builtin_module_names: ('_abc', '_ast', '_bisect', '_blake2', '_codecs', 
'_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', 
'_codecs_tw', '_collections', '_contextvars', '_csv', '_datetime', 
'_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5', 
'_multibytecodec', '_opcode', '_operator', '_pickle', '_random', '_sha1', 
'_sha256', '_sha3', '_sha512', '_signal', '_sre', '_stat', '_statistics', 
'_string', '_struct', '_symtable', '_thread', '_tracemalloc', '_warnings', 
'_weakref', '_winapi', '_xxsubinterpreters', 'array', 'atexit', 'audioop', 
'binascii', 'builtins', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools', 
'marshal', 'math', 'mmap', 'msvcrt', 'nt', 'parser', 'sys', 'time', 'winreg', 
'xxsubtype', 'zlib')
sys.byteorder: little
sys.dont_write_bytecode: Fa

[issue41299] Python3 threading.Event().wait time is twice as large as Python27

2020-07-21 Thread SD


SD  added the comment:

So there is no advised way around this then. I am currently using time.sleep() 
to hit my 60hz.

--

___
Python tracker 
<https://bugs.python.org/issue41299>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com