By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Threads and sys.excepthook

P: n/a
Hello guys,

I have this problem and i don't know any workarounds yet. Im
implementing a DB Connection pool, which initially creates 20
connections and keep them in a dictionary. It also implements a method
for allowing external method/classes to get a connection from that pool.
he main issue is that, from a testing app, I create a loop like this to
test the pool:

import thread
import sys
import seen #this is my module

DB = seen.DBManager()

def test(name):
try :
idc,conn = DB.get_conn()
print "Thread: ",name," -- ",DB," ID: ",idc

except :
print sys.exc_info()[0]
print sys.exc_info()[1]
print "ERROR IN HERE"
return

for i in xrange(20) :
try:
name = 'THREAD' + str(i)except:
thread.start_new(test, (name,)) #(1)
except:
print 'An Exception Ocurred'
print sys.exc_info()[0]
print sys.exc_info()[1]
But when i run this code, The code works fine the first 5 times. the
rest, all i get is this:

SIZE: 20
Thread: THREAD0 -- <seen.DBManager object at 0x403ca7ec> ID: 0
SIZE: 19
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:

And if put a time.sleep(1) after the thread.start_new(test,
(name,)) #(1) part, then it does it all perfectly.

I dont know what is causing the problem, maybe the threads are spawning
too fast? OS issues?? python issues??

Im running Gentoo GNU/Linux and Python2.4

Thanks in advance,

Jesús Rivero - (Neurogeek)
Mar 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jesus Rivero - (Neurogeek) wrote:
Original exception was:
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:

And if put a time.sleep(1) after the thread.start_new(test,
(name,)) #(1) part, then it does it all perfectly.


Looks like the interpreter is shutting down before all the exception
processing finishes.

-Jonathan

Mar 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.