Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Questions on Threading

0 views
Skip to first unread message

Tim Peters

unread,
Jun 26, 2006, 4:27:51 PM6/26/06
to pytho...@python.org
[j.c.sackett]
> I'm using the threading module to accomplish some distributed processing on
> a project, and have a basic (I hope) question that I can't find an answer to
> elsewhere.
>
> I've noted that there's a lot of documentation saying that there is no
> external way to stop a thread,

True.

> and yet when creating a thread through the threading module I can see
> that it has a method called _Thread__stop, which does indeed stop it.

You're misreading the code then. __stop() is used internally by a
thread T to record when T itself knows it's _about_ to stop. Other
threads may be blocked in T.join() calls, and the purpose of T calling
T.__stop() is to notify such threads they can proceed.

> Is this in any way dangerous ( i.e. doesn't actually stop the thread,

That's right.

> or causes other thread timing issues down the road?)

If you call T.__stop(), T will keep running (exactly as if you hadn't
called it), but threads waiting on T.join() will think T has stopped.

> Or is there some other reason that there is officially no stop method?

Python never offered it primarily for the same reasons Java regretted
offering it (so much so that Java eventually deprecated it):

http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html

0 new messages