[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

threading/Queue: join() and task_done() not working? (deadlock

Gal Aviel

2/27/2008 7:07:00 PM

Hello All,

I'm seeing strange behavior where one thread waits on a queue using join() and
the later (or so I think, according to order of the printing in STDOUT) another
thread calls task_done() on the very same queue, however the first thread does
not wake up, it keeps blocking forever.

I'm using a queue of size 1, my print's:

# @115000 : DEBUG PY wait(): waiting for task_done
# on <Queue.Queue instance at 0x416c7a8c>
# @115000 : DEBUG PY callback_cb() - 2
# @115000 : DEBUG PY callback_cb() - signaling
# task_done on <Queue.Queue instance at 0x416c7a8c>
# @115000 : DEBUG PY callback_cb() - 3

As you can see, the queue object is the same on both threads.

Any help would be greatly appreciated, since I've spent days and days on this
already !!

Python 2.5.1, SUSE LINUX Enterprise Server 9.

Thanks in advance, Gal Aviel.





8 Answers

Raymond Hettinger

2/27/2008 7:43:00 PM

0

On Feb 27, 11:06 am, Gal Aviel <galav...@yahoo.com> wrote:
> Hello All,
>
> I'm seeing strange behavior where one thread waits on a queue using join() and
> the later (or so I think, according to order of the printing in STDOUT) another
> thread calls task_done() on the very same queue, however the first thread does
> not wake up, it keeps blocking forever.
>
> I'm using a queue of size 1, my print's:


Does the problem persist with a queue size of 2?


Raymond

7stud --

2/27/2008 9:14:00 PM

0


Gal Aviel wrote:
> Hello All,
>
> I'm seeing strange behavior where one thread waits on a queue using join() and
> the later (or so I think, according to order of the printing in STDOUT) another
> thread calls task_done() on the very same queue,

What is task_done()? The python docs don't list any such function.

Dennis Lee Bieber

2/28/2008 8:30:00 AM

0

On Wed, 27 Feb 2008 13:14:25 -0800 (PST), 7stud <bbxx789_05ss@yahoo.com>
declaimed the following in comp.lang.python:

>
> Gal Aviel wrote:
> > Hello All,
> >
> > I'm seeing strange behavior where one thread waits on a queue using join() and
> > the later (or so I think, according to order of the printing in STDOUT) another
> > thread calls task_done() on the very same queue,
>
> What is task_done()? The python docs don't list any such function.

I didn't even know Queue objects /had/ a join() method... The only
..join() I'm familiar with is the one that waits for a thread to
complete... <G>
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/

Gal Aviel

2/28/2008 8:47:00 AM

0

7stud <bbxx789_05ss <at> yahoo.com> writes:


> What is task_done()? The python docs don't list any such function.


I'm using Python 2.5 and it's in the docs ...

Gal Aviel

2/28/2008 8:49:00 AM

0

Dennis Lee Bieber <wlfraed <at> ix.netcom.com> writes:

> I didn't even know Queue objects /had/ a join() method... The only
> .join() I'm familiar with is the one that waits for a thread to
> complete... <G>

Well it's probably new in Python 2.5 although I'm not sure.




Gal Aviel

2/28/2008 8:50:00 AM

0

Raymond Hettinger <python <at> rcn.com> writes:


> Does the problem persist with a queue size of 2?
>
> Raymond
>
Unfortunately yes.



7stud --

2/28/2008 11:42:00 AM

0

On Feb 28, 1:47 am, Gal Aviel <galav...@yahoo.com> wrote:
> 7stud <bbxx789_05ss <at> yahoo.com> writes:
>
> > What is task_done()?  The python docs don't list any such function.
>
> I'm using Python 2.5 and it's in the docs ...

According to the docs, join() unblocks only after you call task_done()
for every item that was entered into the Queue. However, just because
the Queue size is 1 doesn't mean there aren't other items waiting to
be added to the Queue. With one item in the Queue, presumably the
task-count is 1. But, if you get() an item out of the Queue and
another item is waiting to be added to the Queue, then it seems likely
that the task_count will jump to 2 immediately after calling get().
Thereafter, a call to task_done() will decrement the task_count to 1,
which means join() will continue blocking.

Please recognize that it is very difficult to debug imaginary code.
If you want some help that is more relevant, then post a short example
that demonstrates your problem. Do not post some lengthy program with
cryptic variable names.

Dennis Lee Bieber

2/29/2008 6:55:00 AM

0

On Thu, 28 Feb 2008 08:48:51 +0000 (UTC), Gal Aviel <galaviel@yahoo.com>
declaimed the following in comp.lang.python:

>
> Well it's probably new in Python 2.5 although I'm not sure.
>
After checking the 2.5 documents online, it is...

Apparently some means of allowing the main process to /wait/ until
the daemon thread have nothing left to work on, instead of suddenly
killing them mid-effort when the main process exits because no other
means of synchronizing was done.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/