[Python-bugs-list] [ python-Bugs-231189 ] Crash when Python Re-Initialized with Daemon Threads

noreply@sourceforge.net noreply@sourceforge.net
Tue, 20 Mar 2001 11:56:36 -0800


Bugs item #231189, was updated on 2001-02-05 15:04
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=231189&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
Priority: 5
Submitted By: Justin D. Pettit (jpettit)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Crash when Python Re-Initialized with Daemon Threads

Initial Comment:
When "threadCrash.c" is built and run, it will fail with a segmentation fault.  It appears Py_Finalize is not properly cleaning up the threads.  Under the "Bugs and caveats" section of Py_Finalize in the Python/C API Reference Manual (api\initialization.html), it mentions various problems, but doesn't mention this one.

I've tested this with Python 2.0 on Win2K, Linux, and OpenBSD.

--------- threadCrash.c ---------

#include "Python.h"

#define THREAD_FILE "simpleThread.py"

main(int argc, char **argv)
{
    FILE *threadScript;

    Py_SetProgramName(argv[0]);

    while (1)
    {
        Py_Initialize();

        threadScript = fopen(THREAD_FILE, "r");

        PyRun_SimpleFile(threadScript, THREAD_FILE);

        fclose(threadScript);

        // Destroy our interpreter for a clean restart
        Py_Finalize();
    }
}

--------- simpleThread.py ---------

import threading
import time

class simple(threading.Thread):
    def __init__(self, idNum):
        threading.Thread.__init__(self)
        self.idNum = idNum

    def run(self):
        while 1:
            print self.idNum
            time.sleep(1)

for i in range(5):
    a = simple(i)
    a.start()

--------- end ---------

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-03-20 11:56

Message:
Logged In: YES 
user_id=6380

It's not really possible to do something about this.  There
is no way to kill a thread (for very good reasons having to
do with releasing resources such as locks) if there are
threads running (daemon or otherwise) when Py_Finalize() is
called.  I agree that it's a pain that this can crash, but,
alas, I can't fix it.

So I'm closing this bug report. :-(

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-02-09 15:33

Message:
Assigned to Guido.

jpettit, the whitespace isn't actually destroyed, that's simply what browsers *do* with runs of whitespace (i.e., they collapse them).  The leading whitespace is still present in the database, and you'll see it e.g. in the email SourceForge generates.  We have a request outstanding with SourceForge to do a better job of this on the web pages (e.g., generating   instead of literal spaces).

----------------------------------------------------------------------

Comment By: Justin D. Pettit (jpettit)
Date: 2001-02-05 15:08

Message:
Sorry, the subject line is misleading.  I had originally thought this had something to do with daemonic threads, but it seems to be a general thread issue.  Also, it appears that SourceForge likes to eat proceeding white space, which has munged my Python code.  It should be fairly straight-forward, though, to determine what I meant.  Is there a preferred way to submit Python code to SourceForge?

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=231189&group_id=5470