Python or OS forking/threading problem?

David Fisher python at rose164.wuh.wustl.edu
Thu Mar 23 20:41:30 EST 2000


----- Original Message -----
From: "Andrew M. Kuchling" <akuchlin at mems-exchange.org>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, March 23, 2000 9:55 AM
Subject: Re: Python or OS forking/threading problem?



> Unless ... I noticed something suspicious along the way; look at this
> code from floatsleep() in Modules/timemodule.c:
>
> Py_BEGIN_ALLOW_THREADS
> if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
>     Py_BLOCK_THREADS
>     #ifdef EINTR
>     if (errno != EINTR) {
>     #else
>     if (1) {
>     #endif
>         PyErr_SetFromErrno(PyExc_IOError);
>         return -1;
> }
> }
> Py_END_ALLOW_THREADS
>
> Py_BLOCK_THREADS is for leaving a {BEGIN,END}_ALLOW_THREADS block (see
> ceval.h), but this code doesn't always exit; if errno == EINTR, the
> flow would be Py_BEGIN_ALLOW_THREADS; Py_BLOCK_THREADS;
> Py_END_ALLOW_THREADS.  I suspect the BLOCK_THREADS should be moved to
> inside the if, so it's only executed when the function actually
> returns unexpectedly.  But I don't know if this might be the root of
> the problem.

Are you using a CVS copy of Python?  Because my source for floatsleep()
doesn't look like that.  I'm using the 1.5.2 source and the code looks like
this:

 Py_BEGIN_ALLOW_THREADS
 if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
     Py_BLOCK_THREADS
     PyErr_SetFromErrno(PyExc_IOError);
     return -1;
 }
 Py_END_ALLOW_THREADS

I agree that the usage you quoted is fishy, but the above looks fine.  And
forking in multiple threads locks up on my RH6.1 box also, so I don't think
the problem is in sleep.

I ran the code that you cleaned up with buffering turned off, and it seemed
to me to be locking up on the os._exit() call.  I remember Tim Peters
posting a while back about an obscure race condition with a lot of processes
being created and killed.  I'm no guru, but I'd place my bet that this is
the very problem.

My solution to the problem goes like this:

    Patient: "Doctor! My arm hurts when I go like this."

    Doctor: "So don't do that."

David





More information about the Python-list mailing list