threading appears to run threads sequentially

Currently in python, threads get changed after executing some specified amount of bytecode instructions. They don’t run at the same time. You will only have threads executing in parallel when one of them calls some I/O-intensive or not python-affecting module that can release GIL (global interpreter lock).

I’m pretty sure you will get the output mixed up if you bump the number of loops to something like 10000. Remember that simply spawning the second thread also takes “a lot” of time.

Leave a Comment