Staging
v0.5.1
https://github.com/python/cpython
Revision 69e1309fd4faf7e5e4f74f54678f9648316aae37 authored by Jeffrey Yasskin on 28 February 2008, 06:09:19 UTC, committed by Jeffrey Yasskin on 28 February 2008, 06:09:19 UTC
new thread had started. At least on my MacBook Pro, that wound up sleeping for
a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely
certain that the thread has started, and return more quickly (217us).

Before:
$  ./python.exe -m timeit -s 'from threading import Thread'  't = Thread(); t.start(); t.join()'
100 loops, best of 3: 10.3 msec per loop
$  ./python.exe -m timeit -s 'from threading import Thread; t = Thread()'  't.isAlive()'
1000000 loops, best of 3: 0.47 usec per loop

After:
$  ./python.exe -m timeit -s 'from threading import Thread'  't = Thread(); t.start(); t.join()'
1000 loops, best of 3: 217 usec per loop
$  ./python.exe -m timeit -s 'from threading import Thread; t = Thread()'  't.isAlive()'
1000000 loops, best of 3: 0.86 usec per loop

To be fair, the 10ms isn't CPU time, and other threads including the spawned
one get to run during it. There are also some slightly more complicated ways to
get back the .4us in isAlive() if we want.
1 parent 180997b
History
Tip revision: 69e1309fd4faf7e5e4f74f54678f9648316aae37 authored by Jeffrey Yasskin on 28 February 2008, 06:09:19 UTC
Thread.start() used sleep(0.000001) to make sure it didn't return before the
Tip revision: 69e1309
File Mode Size
Demo
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Python
RISCOS
Tools
.hgtags -rw-r--r-- 3.2 KB
LICENSE -rw-r--r-- 13.4 KB
Makefile.pre.in -rw-r--r-- 36.1 KB
README -rw-r--r-- 54.2 KB
configure -rwxr-xr-x 642.5 KB
configure.in -rw-r--r-- 98.0 KB
install-sh -rwxr-xr-x 7.0 KB
pyconfig.h.in -rw-r--r-- 28.1 KB
setup.py -rw-r--r-- 71.8 KB

README

back to top