Killing a thread

pauljolly at my-deja.com pauljolly at my-deja.com
Fri Aug 4 04:20:38 EDT 2000


Thanks, but this does not kill the thread. I have tried this within the
python shell.

For example, I started a thread in which I used time.sleep(120). Then I
used join(10) to see whether after ten seconds join would kill the
sleep thread still running. Join waited the ten seconds (sleep() was
still running as it is set to 120 seconds), I then checked to see which
threads were still running, and one of them was the thread which runs
the function sleep(). Hence join did not kill the thread at all.

Seems to me, that this is a slight problem within Python. For example,
no timeout mechanism is provided for urllib.urlopen() and the threading
capabilities do not allow for a timeout mechanism either. Something
that I am told, in a response to my post from another newsgroup member,
is not set to change in future versions of python.

Regards

Paul

In article <75F7304BB41CD411B06600A0C98414FCB36839 at ORSMSX54>,
  "Daley, Mark W" <mark.w.daley at intel.com> wrote:
> I was just reading about this.  Here is the example:
>
> A Thread object t supports the following methods:
>
> <snip>
>
> t.join([timeout])
>
> 	Waits until the thread terminates or a timeout occurs.
[timeout] is
> a floating-point number specifying a timeout in seconds.  A thread
can't
> join itself and it's an error to join a thread before it has been
started.
>
> <snip>
>
> This comes from Python Essential Reference (which, BTW, bears a
remarkable
> resemblance to the documentation supplied with the Python
distribution!)
>
> - Mark
> ----------------------------------------------
> The opinions expressed are mine, and are not necessarily those of my
> employer.
>
> -----Original Message-----
> From: pauljolly at my-deja.com [mailto:pauljolly at my-deja.com]
> Sent: Thursday, August 03, 2000 7:33 AM
> To: python-list at python.org
> Subject: Killing a thread
>
> Dear All,
>
> I have a slight problem and I cannot seem to find the answer. I have
> decided that using threads would be a good idea for my program written
> in Python. I want to start a thread that retrieves a URL. Now, after a
> certain time, say 30 seconds or one minute, I want to test whether
that
> thread is still running. If the thread is still running I want to kill
> that thread. I am using threading module, and currently Thread() class
> to create a new class object. I then start the thread using start()...
> but I do not know where to go from here for the testing and the
killing
> part described above. Could someone please help?
>
> I will in the end start about seven threads simultaneously and check
to
> see whether any of them are running after a specified time. If there
> are threads running, kill them.
>
> Best regards,
>
> Paul
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list