473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Crash in thread on program termination

I have several programs that have two or more threads. The threads that are not the main thread are daemon threads, i.e. the fact that they are running should not stop the program from terminating if the main thread (the only non-daemon thread) terminates. I do not join to these threads, but just run off the end of the main module to terminate the program. I'm using Python 2.3.4. I occasionally get the following error:

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
What seems to be happening is that at the time the thread is stopped, the threading module object is no longer in an unhealthy state. I.e. threading.currentThread is None. I hacked around this problem by substituting my own code for _Condition.notifyAll() that would not call notify() if there were no waiters to be notified. However, that merely allowed the code to get a little further, before crashing with a similar problem, i.e. threading._StringIO is None instead of being a class object.

Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 443, in __bootstrap
s = _StringIO()
TypeError: 'NoneType' object is not callable
I turned on threading.__debug__ and threading._VERBOSE to get some debug output, and one thing that is strange is that I don't get the debugging output I expect.

# From threading.Thread.__bootstrap():
try:
self.run()
except SystemExit:
if __debug__:
self._note("%s.__bootstrap(): raised SystemExit", self)
except:
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
s = _StringIO()
_print_exc(file=s)
_sys.stderr.write("Exception in thread %s:\n%s\n" %
(self.getName(), s.getvalue()))
else:
if __debug__:
self._note("%s.__bootstrap(): normal return", self)
finally:
self.__stop() # Line 451
I.e. I would expect to get one of the messages ('raised SystemExit', 'unhandled exception', or 'normal return') before self.__stop() is called at line 451. However, I do not see any of those messages.

Any ideas or suggestions? I am baffled.

Thanks,

Alec Wysoker
Jul 18 '05 #1
1 2414
Alec Wysoker wrote:
I have several programs that have two or more threads. The threads
that are not the main thread are daemon threads, i.e. the fact
that they are running should not stop the program from terminating
if the main thread (the only non-daemon thread) terminates.

Traceback (most recent call last): [...] File "C:\Python23\lib\threading.py", line 238, in notify
currentThread() # for side-effect
TypeError: 'NoneType' object is not callable

What seems to be happening is that at the time the thread is stopped, the threading
module object is no longer in an unhealthy state.
I.e. threading.currentThread is None.


In a nutshell, the interpreter is dismantling itself while the
daemon threads merrily continue to run -- or attempt to. During
one of the steps in this dismantling process, the interpreter
goes through and rebinds all the globals in all modules to the
None object. You're seeing the effect of a daemon thread
encountering the inevitable bad effects of this.

For background, search the list archives and focus on messages
written by Tim Peters. Also try Googling the web for, say,
"python interpreter daemon thread shutdown nonetype" or
something... there are various not entirely conclusive threads
on the subject here and there.

I'm not sure there is a generally acceptable solution. You'll
notice that the ultimate response of the code in __bootstrap()
is still to try to print to stderr... which is a harmless but
otherwise perhaps distracting thing to do.

In my own code where this was a bother, I have something like
the following at the highest levels of the run() method of
my daemon threads:

def run(self):
try:
# do real stuff here
except Exception, ex:
if (self.isDaemon() and
isinstance(ex, AttributeError) and
ex[0].startswith("'NoneType'")):
pass

In other words, I'm attempting to catch those specific types of
spurious error and avoid letting __bootstrap() have its say.
At the moment, 98% of the spurious messages are gone and that's
good enough for my purposes...

-Peter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thanvir | last post by:
We have an application that runs under Linux, solaris. The Application was developed in C++ under linux, it supports both Oracle and Informix database. For database connectivity in oracle it...
1
by: tony | last post by:
hi. my NET application is using mixed c++ dll ( managed and unmanaged) in that dll , im calling api's of unamanged dll. my application crash with no exception or warning. its hard to...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
1
by: bdoyle | last post by:
python-help@python.org] Hi Python Experts, I am developing a Python interface to an existing (multithreaded) c++ api. I have it working on several platforms (linux, solaris, irix, windoze)...
0
by: Sir Spamallot | last post by:
Hi there, Previously when handling the termination of threads I had just called the abort method and caught it in a try catch block in the thread callback. After recently learning that this was...
2
by: robert | last post by:
There is a strange freeze/crash only on dual core machines: I have a python app (Python 2.3.5 /Pythonwin build 203 / Windows) running with no stability problems on normal machines (Or a crash is...
6
by: bjornms | last post by:
The application i build in C#.net is crashing once a month. I can't reproduce the crash. Is there a way to track down where the program crashes, without putting logging everywhere in the code?...
1
by: [david] | last post by:
What am I doing wrong? I'm trying to capture stdErr in a multi-threaded program. This code crashes wxPython with /Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/ What I'm...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.