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