473,395 Members | 1,377 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.

2.4 crashes when try to exit app and mulitple threads active

An application I am developing executes many threads and then has a
"monitor" part that waits for certain events. One of these events causes
the application to have to shutdown. On shutdown the monitor part
notifies the threads of a shutdown, and the threads must cleanup and exit.
When all threads have exited the monitor itself exits.

The traceback below occured on a shutdown. At the time there was only one
thread running, however the same traceback occurs with many threads active.

Some things I've observed:
1 - my application is able to complete successfully,

2 - it appears to be only in python 2.4. - does not occur with 2.3.1.

3 - it is not consistent, there are times when there is no traceback

4 - more likely to occur the longer a thread/application has run.

5 - does occur frequently enough (50% of the time) to be a problem

I do not know how to investigate further. Any help or suggestions on how
to investigate this and resolve would be much appreciated.

Thanks.
---------------------------------------------------------------------------------
Error traceback:
-----------------
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.4/atexit.py", line 22, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.4/threading.py", line 636, in __exitfunc
self._Thread__delete()
File "/usr/lib/python2.4/threading.py", line 522, in __delete
del _active[_get_ident()]
KeyError: 16384
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.4/atexit.py", line 22, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.4/threading.py", line 636, in __exitfunc
self._Thread__delete()
File "/usr/lib/python2.4/threading.py", line 522, in __delete
del _active[_get_ident()]
KeyError: 16384

Software environment:
-----------------------
*********************************************
*** SYSTEM INFORMATION ***
*** (Sat Mar 19 19:15:03 EST 2005) ***
*********************************************
Host or node name : poseidon
Machine type : i686
Operating system : Linux
Kernel version : 2.4.29
Linux Distribution : Slackware 10.1.0
*********************************************
Python 2.4 (#1, Jan 1 2005,21:33:55) [GCC 3.3.4] on linux2
Gnu make 3.80
util-linux 2.12p
modutils 2.4.27
e2fsprogs tune2fs
Linux C Library 2.3.4
Dynamic linker (ldd) 2.3.4
Linux C++ Library 5.0.6
Procps 3.2.3
Net-tools 1.60
Kbd 1.12
Sh-utils 5.2.1
*********************************************
Modules Loaded:
nfs
lockd
sunrpc
ppp_deflate
zlib_inflate
zlib_deflate
bsd_comp
ppp_async
ppp_generic
slhc
emu10k1
ac97_codec
soundcore
xfs
ne2k-pci
8390
crc32
*********************************************
gcc version 3.3.4
Reading specs from
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/specs Configured with:
.../gcc-3.3.4/configure --prefix=/usr --enable-shared
--enable-threads=posix --enable-__cxa_atexit --disable-checking
--with-gnu-ld --verbose --target=i486-slackware-linux
--host=i486-slackware-linux
Thread model: posix
*********************************************

Jul 18 '05 #1
3 1855
Maxwell Hammer wrote:
An application I am developing executes many threads and then has a
"monitor" part that waits for certain events. One of these events causes
the application to have to shutdown. On shutdown the monitor part
notifies the threads of a shutdown, and the threads must cleanup and exit.
When all threads have exited the monitor itself exits.

The traceback below occured on a shutdown. At the time there was only one
thread running, however the same traceback occurs with many threads active.


When you say "only one thread running", did you mean only
one monitor thread in addition to the main thread, or did
you really mean only the main thread was active at this time?

Also, are you doing something odd to terminate threads
here, and could you have screwed things up yourself?
The code in question is at the end of the MainThread's
__exitfunc() method, and normally this would be executing
only after all other threads had terminated, and should
be safe. It appears as though the _active dictionary that
tracks threads has been modified by someone else.

Can you post a small self-contained example that
reproduces the problem?

-Peter

Jul 18 '05 #2
On Sat, 19 Mar 2005 22:35:39 -0500, Peter Hansen wrote:
When you say "only one thread running", did you mean only
one monitor thread in addition to the main thread, or did
you really mean only the main thread was active at this time?
I meant there was the main app and one thread. The problem
does not occur when there are no threads running and the app
has to exit.
Also, are you doing something odd to terminate threads
here, and could you have screwed things up yourself? Very likely - it has happened before :-)
The code in question is at the end of the MainThread's
__exitfunc() method, and normally this would be executing
only after all other threads had terminated, and should
be safe. It appears as though the _active dictionary that
tracks threads has been modified by someone else.
That is what it looks like to me. It seems that the interpreter
is trying to delete a non-existant thread
Can you post a small self-contained example that
reproduces the problem?

This will be difficult to do...but perhaps if I give a summary:

def main():
...initialize/configure
...wait for certain events
...based on events launch appropriate thread as follows:

thread.start_new_thread(event_module.run, (StateValues, (job_parms)))
...

def event_module.run(StateValues, (job_parms)):
...initialize/configure
while (1):
Return = os.system(RunString)

if Shutdown flag exists: #thread detects here if needs to exit
save_job(parms)
cleanup_exit(message, exit_code)
if Return == 0: # SUCCESS
break
elif Return == 1: # ERROR
...
elif Return == 7: # ERROR
...

def cleanup_exit(message, exit_code):
remove temp files
log message, etc
return

So at shutdown, any threads running save their state to a job file
then simply do a return.

Hope this helps...also I use command line apps to program like Nedit.

Know of any visual python debuggers? I know there is "idle"...
any others, better ones?
Have you heard of "eric" python ide. Is it good? - it would have debug
capabilities but is dependent on many libraries I think.

thanks a lot.

Jul 18 '05 #3
Maxwell Hammer wrote:
On Sat, 19 Mar 2005 22:35:39 -0500, Peter Hansen wrote:
When you say "only one thread running", did you mean only
one monitor thread in addition to the main thread, or did
you really mean only the main thread was active at this time?


I meant there was the main app and one thread. The problem
does not occur when there are no threads running and the app
has to exit.


Okay, but make sure you understand that it's not possible
to have "no threads running" unless your application has
already exited. There is *always* at least the main thread.
I think you know that, but it's confusing when you keep
talking as though the main thread doesn't exist.
The code in question is at the end of the MainThread's
__exitfunc() method, and normally this would be executing
only after all other threads had terminated, and should
be safe. It appears as though the _active dictionary that
tracks threads has been modified by someone else.


That is what it looks like to me. It seems that the interpreter
is trying to delete a non-existant thread


More than that, it's the MainThread in threading.py trying
to delete itself at exit, and that should always be possible
unless you've done Something Bad (or if this is indeed some
Python bug).
Can you post a small self-contained example that
reproduces the problem?


This will be difficult to do...but perhaps if I give a summary:

def main():
...initialize/configure
...wait for certain events
...based on events launch appropriate thread as follows:

thread.start_new_thread(event_module.run, (StateValues, (job_parms)))
...


Unfortunately, pseudo code like that is of little help.

It does, however, raise a question. You are using the thread.py
module here, yet the exception is being generated as a result
of the MainThread object (that is created when you import
the threading.py module) trying to exit: how can it be that
threading.py is imported when you are using only the thread
module yourself? Other code that you aren't aware of? More
complexity than your snippets suggest?

You really need to reduce this down to a simple piece of code
that reproduces the problem if you hope to solve it. Race
conditions are just about the hardest thing in the world to
troubleshoot, and while you could report a bug here, without
code to reproduce the chances of someone finding and fixing
it are just about nil.

-Peter
Jul 18 '05 #4

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

Similar topics

0
by: Adam Kempa | last post by:
Hello I've been installed Postgres 7.4.2 on FreeBSD system and when load average grow up i've error in postgres like this: ERROR: permission denied for function varchar ERROR: permission...
3
by: Seamus Hand | last post by:
I am trying to write a component maintenance application and have tables as follows Part Part # Part Description Active (y/N) as these parts are obsoleted, ie Active changes to N, then I...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
7
by: Mark B | last post by:
Hi I was wondering if someone could help me with the syntax for some VB.Net ASPX code to: - Start 20 threads - End all threads after the sooner of 10 seconds or if all of the threads...
2
by: robert | last post by:
When employing complex UI libs (wx, win32ui, ..) and other extension libs, nice "only Python stack traces" remain a myth. Currently I'm hunting again a rare C-level crash bug of a Python based...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
1
by: billsahiker | last post by:
Why is my application crashing on a windows 98 machine? It runs fine on the development machine with xp pro.It was developed with VS2005 in VB. I installed framework 2 and windows installer 2 on...
41
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as...
2
by: jaddle | last post by:
I program I'm writing crashes when it exits with a segfault. I'm runnning under linux. Using gdb, i see that the crash happens after the last line of main(), which is just a return(EXIT_SUCCESS); If...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.