[Stackless] Channels between threads
Simon Pickles
sipickles at hotmail.com
Sat Jan 19 22:58:26 CET 2008
Hi,
Following the example, stacklessfileThreadPool, I have written a mySQL
access version. It uses almost identical code to the example, doing SQL
queries instead of file operations.
I thought it was working at first but it has a problem.
Say I have 4 threads in the pool, then I can do 4 SQL requests before it
stops. Each thread can only hear one work request, even tho this is
supposed to be a while(1) loop.
Logging the code I can see the problem is here, in Class WorkerThread.run():
def run(self):
while not self._dismissed.isSet():
# thread blocks here, if queue empty
request = self.workRequestQueue.get()
logger.DAT("%s received request with channel %s: %s" %
(self, request.ch, request.s))
logger.DAT("Work Queue size after get(): %d" %
self.workRequestQueue.qsize())
try:
data = self.conn.execute(request.ch, request.s)
#logger.DAT("%s RESULT: %s" % (self,str(data)))
#self.resultsChannel.send((data, request.ch,
request.requestID))
logger.DAT("Sending result thru: %s, balance: %d" %
(request.ch, request.ch.balance))
request.ch.send(data)
except:
exc, val, ad = sys.exc_info()
logger.DAT("ERROR in %s: %s - %s" % (self, exc, val))
request.ch.send_exception(exc, val)
logger.DAT("Ready for new work") # <<<<<< This line is
never reached, request.ch.send seems to block
I understand that channel.send will block until a receive is made.
However, this receive is being made in the requesting thread and the
results are successfully received!
So why does this code never reach the line "Ready for new work"?
Before the ch.send, the balance on the channel is 0.
In the receiving code, the balance on the channel after the receive is
1, even tho the data IS received.
Can anyone imagine why this might be? or have I misunderstood?
Thanks for your help
Simon
.****
**
**
--
Linux user #458601 - http://counter.li.org.
More information about the Stackless
mailing list