[Python-bugs-list] PyOS_AfterFork (PR#392)
fdrake@beopen.com
fdrake@beopen.com
Thu, 6 Jul 2000 01:43:53 -0400 (EDT)
jon@dstc.edu.au writes:
> In posixmodule.c:posix_fork, the function PyOS_AfterFork is called for
> both the parent and the child, despite the docs stating that it should
> be called in the new (child) process.
>
> This causes problems in the parent since the forking thread becomes the
> main thread according to the signal module.
>
> e.g. the following program fails with the frustrating message:
> "ValueError: signal only works in main thread"
After making the appropriate change in posixmodule.c, I get:
Exception in thread Thread-1:
Traceback (most recent call last):
File "./../Lib/threading.py", line 376, in __bootstrap
self.run()
File "./../Lib/threading.py", line 364, in run
apply(self.__target, self.__args, self.__kwargs)
File "fork-signal.py", line 6, in foo
os.wait(pid, 0)
TypeError: wait requires exactly 0 arguments; 2 given
You're still right about the bug in posix_fork(), I think. I'll
check in the fix (patch below) once someone else confirms this.
Thanks for reporting this!
-Fred
--
Fred L. Drake, Jr. <fdrake at beopen.com>
BeOpen PythonLabs Team Member
Index: Modules/posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.141
diff -c -r2.141 posixmodule.c
*** Modules/posixmodule.c 2000/06/30 23:58:05 2.141
--- Modules/posixmodule.c 2000/07/06 05:43:33
***************
*** 1755,1761 ****
pid = fork();
if (pid == -1)
return posix_error();
! PyOS_AfterFork();
return PyInt_FromLong((long)pid);
}
#endif
--- 1755,1762 ----
pid = fork();
if (pid == -1)
return posix_error();
! if (pid == 0)
! PyOS_AfterFork();
return PyInt_FromLong((long)pid);
}
#endif