Skip to content

Commit 5c603a7

Browse files
committed
Replace the deprecated PyOS_AfterFork() function
Container_attach_and_possibly_wait() fails in Python 3.13 with "PyMutex_Unlock: unlocking mutex that is not locked" if PyOS_AfterFork() is used. Signed-off-by: Andreas Vögele <andreas@andreasvoegele.com>
1 parent ac1f123 commit 5c603a7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lxc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ static int lxc_attach_python_exec(void* _payload)
198198
* container. As lxc_attach() calls fork() PyOS_AfterFork should be called
199199
* in the new process if the Python interpreter will continue to be used.
200200
*/
201+
#if PY_VERSION_HEX >= 0x030700F0
202+
PyOS_AfterFork_Child();
203+
#else
201204
PyOS_AfterFork();
205+
#endif
202206

203207
struct lxc_attach_python_payload *payload =
204208
(struct lxc_attach_python_payload *)_payload;
@@ -748,8 +752,14 @@ Container_attach_and_possibly_wait(Container *self, PyObject *args,
748752
if (!options)
749753
return NULL;
750754

755+
#if PY_VERSION_HEX >= 0x030700F0
756+
PyOS_BeforeFork();
757+
#endif
751758
ret = self->container->attach(self->container, lxc_attach_python_exec,
752759
&payload, options, &pid);
760+
#if PY_VERSION_HEX >= 0x030700F0
761+
PyOS_AfterFork_Parent();
762+
#endif
753763
if (ret < 0)
754764
goto out;
755765

0 commit comments

Comments
 (0)