4 ms·
An Introduction to Thread Programming in Python
- kobs 18y agoAn introduction I've found helpful: http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf
- rit 18y agoJust keep in mind that via the GIL (Global Interpreter Lock) Python limits the system to executing one bytecode instruction at a time - Threads execute in a more serial fashion, switching context every 100 bytecode instructions or so (e.g. let Thread 1 have 100 bytecodes, then switch to Thread 2). This is a good thing and a bad thing - internally it keeps some non-threadsafe components from asploding but can be confusing and frustrating if you're looking for true multithreading. There are some implementations of Python that don't use a GIL, such as stackless, if you're looking for true multithreading.
- ardit33 18y agoPrimitive. Not real threads, more like co-routines. This will be a real limitation for python, especially when multi-core CPUs are the norm.