3 ms·
The thing about Python is that it is a scripting language. Importing a Python module involves executing arbitrary code. Here is a quick rundown of how a deadlo
by sirclueless 14y ago
The thing about Python is that it is a scripting language. Importing a Python module involves executing arbitrary code.
Here is a quick rundown of how a deadlock can occur:
1. The main module runs in Thread #1, which imports module "foo".
2. Module "foo" has code at the top level that starts a new thread (Thread #2), and then blocks waiting for it to do something.
3. In Thread #2, someone calls datetime.strptime(). This deadlocks because now Thread #2 needs to import "_strptime" but Thread #1 holds the Global Import Lock because it is importing "foo".
- GauntletWizard 14y agoThis is exactly the use case for Recursive Mutexes.
- eurleif 14y agoI don't think so. It sounds like this is about one thread trying to acquire the lock while another holds it, not the same thread trying to acquire the same lock twice.