The thread module (cont)
The main thread
- When Python starts, it runs as a single thread of execution.
- This is called the "main thread."
- On its own, it's no big deal.
- However, if you launch other threads it has some special properties.
Termination of the main thread
- If the main thread exits and other threads are active, the behavior is system dependent.
- Usually, this immediately terminates the execution of all other threads without cleanup.
- Cleanup actions of the main thread may be limited as well.
Signal handling
- Signals can only be caught and handled by the main thread of execution.
- Otherwise you will get an error (in the signal module).
- Caveat: The keyboard-interrupt can be caught by any thread (non-deterministically).
|