[Python] Steal the GIL after fork()'ing

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing a C++ python module, the module needs to fork() a child process and call some python functions in the child process. The child process has only one thread.

    I cannot acquire the GIL before calling fork() because doing so will result in a deadlock.

    If the GIL isn't acquired, after fork(), the child process will see the GIL as locked by other thread which isn't there, and it won't be able to acquire it.

    Is there any way to "steal" the GIL in the child process, since there is only one thread in the child process, it should be safe to do so.

    Continue reading...

Compartilhe esta Página