Threads and sys.excepthook

  • Thread starter Jesus Rivero - (Neurogeek)
  • Start date
J

Jesus Rivero - (Neurogeek)

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)
 
J

Jonathan Ellis

Jesus said:
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
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top