sys.stderr and thread

M

Michele Petrazzo

I have a wxpython application (the main program) and a lot of external
modules (import mymodule) that use always 2 thread (one is my
application and one is twisted with new threadselectreactor).
Sometime when I close my app, I receive a thread error that I want to
redirect to a file (I don't know why this error occur, but this is
another problem...).
I use the redirection of stderr and stdout to a file

This work for all my application, work also for an exception that I
insert for try, but not for the thread error (when this occur). Is
there a solution for redirect all the messages?

This is the exception:

Unhandled exception in thread started by <bound method
Thread.__bootstrap of <Thread(Thread-1, stopped daemon)>>
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 451, in __bootstrap
self.__stop()
File "C:\Python23\lib\threading.py", line 460, in __stop
self.__block.notifyAll()
File "C:\Python23\lib\threading.py", line 256, in notifyAll
self.notify(len(self.__waiters))
File "C:\Python23\lib\threading.py", line 238, in notify
currentThread() # for side-effect
TypeError: 'NoneType' object is not callable

Thanks,
Michele
 
P

Peter Hansen

Michele said:
I have a wxpython application (the main program) and a lot of external
modules (import mymodule) that use always 2 thread (one is my
application and one is twisted with new threadselectreactor).
Sometime when I close my app, I receive a thread error that I want to
redirect to a file (I don't know why this error occur, but this is
another problem...).

This looks like it must be an exception in a *daemon* thread that is
still running even as the Python interpreter dismantles itself at
application exit.
This is the exception:

Unhandled exception in thread started by <bound method
Thread.__bootstrap of <Thread(Thread-1, stopped daemon)>>
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 451, in __bootstrap
self.__stop()
File "C:\Python23\lib\threading.py", line 460, in __stop
self.__block.notifyAll()
File "C:\Python23\lib\threading.py", line 256, in notifyAll
self.notify(len(self.__waiters))
File "C:\Python23\lib\threading.py", line 238, in notify
currentThread() # for side-effect
TypeError: 'NoneType' object is not callable

One of the steps the interpreter takes is to go through all modules and
rebind all globals to None. I suspect currentThread is a global in the
above (although I thought that particular issue was fixed in Python
2.4... are you running an older version?).

The "simplest" thing to do is to ignore this exception because it's
spurious". One way to ignore it is simply to wrap that particular
daemon thread's "run" method with a "try/except: pass" so that all
exceptions are swallowed quietly. Often that's not preferable, however,
since it will of course swallow real exceptions too.

The "safest" thing to do is to terminate that daemon thread before the
application exits. That basically means setting it to be a daemon
thread is sort of pointless, but there's not really a much better solution.

A google search for "python interpreter thread bind global none" or
something awful like that will probably turn up some background
material, likely written by Tim Peters. :)

-Peter
 
M

Michele Petrazzo

Peter said:
One of the steps the interpreter takes is to go through all modules and
rebind all globals to None. I suspect currentThread is a global in the
above (although I thought that particular issue was fixed in Python
2.4... are you running an older version?).

Like you can see (c:\python23), I'm working with python 2.3. I'll try
with 2.4.
The "simplest" thing to do is to ignore this exception because it's
spurious". One way to ignore it is simply to wrap that particular
daemon thread's "run" method with a "try/except: pass" so that all
exceptions are swallowed quietly. Often that's not preferable, however,
since it will of course swallow real exceptions too.

After a lot of tries, I modify the twisted threadselectreactor with your
hack, and now it work.

Thanks a lot,
Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top