473,796 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\li b\threading.py" , line 451, in __bootstrap
self.__stop()
File "C:\Python23\li b\threading.py" , line 460, in __stop
self.__block.no tifyAll()
File "C:\Python23\li b\threading.py" , line 256, in notifyAll
self.notify(len (self.__waiters ))
File "C:\Python23\li b\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.curre ntThread is None. I hacked around this problem by substituting my own code for _Condition.noti fyAll() 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._Stri ngIO is None instead of being a class object.

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

# From threading.Threa d.__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.wri te("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 2452
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\li b\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.curre ntThread 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("'N oneType'")):
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
2422
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 uses OTL (Oracle template library) and for informix it uses ESQL In all the platforms we use GNU C/C++ compiler for building the executable( Version >= 3.3.2)
1
2259
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 find when the crash happen ,and where.
6
3132
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 several serial ports. It only crashes when data is being received on one or more of the serial ports. Could someone please give me some ideas about what would cause a program to terminate in this way? Thanks....
1
1693
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) but I am having a few problems with threading on hp-ux and aix platforms. Here is one of the problems I see.
0
1201
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 a bad way of handling thread termination I am working on terminating threads by using ManualResetEvent's. I have come up with the following code which appears to work very well (at end of message). I would like to know if anyone knows of any...
2
2329
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 so rare, that absolutely nobody obverses it, though the overall majority of users uses single core machines). Threads, network & pythonwin/win32ui all in use. Yet, from 3 users, _all_ using a Dual Processor System (XEON, amd x2 3800+)...
6
4804
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? Is there a way to get a stack trace of the crashing program (by the way, i'm new to C#.net, i have experience in (unmanaged) C++). Thanks in advance.
1
2297
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 trying to do is redirect stderr and stdout to a wxPython text control. In an ideal world, when the worker thread crashes, I should get a stderr message, with no effect on the main thread.
11
3051
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 and IE8. There is no issue when the controls are allowed to complete loading. Can you please tell me the best practice that handles this? Thanks.
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.