Prepare to fork a new child process by acquiring the module-level lock. This should be used in conjunction with _afterFork().
()
| 229 | _lock = threading.RLock() |
| 230 | |
| 231 | def _prepareFork(): |
| 232 | """ |
| 233 | Prepare to fork a new child process by acquiring the module-level lock. |
| 234 | |
| 235 | This should be used in conjunction with _afterFork(). |
| 236 | """ |
| 237 | # Wrap the lock acquisition in a try-except to prevent the lock from being |
| 238 | # abandoned in the event of an asynchronous exception. See gh-106238. |
| 239 | try: |
| 240 | _lock.acquire() |
| 241 | except BaseException: |
| 242 | _lock.release() |
| 243 | raise |
| 244 | |
| 245 | def _afterFork(): |
| 246 | """ |