On 2/16/06, Bob Ippolito <[EMAIL PROTECTED]> wrote:
> On Feb 16, 2006, at 11:45 AM, Gustavo Sverzut Barbieri wrote:
> > On 2/16/06, Mike Orr <[EMAIL PROTECTED]> wrote:
> >>
> >> On 2/16/06, Kevin Dangoor <[EMAIL PROTECTED]> wrote:
> >>>
> >>> On 2/15/06, Mike Orr <[EMAIL PROTECTED]> wrote:
> >>>> Then I discovered if the server is not handling a request, pressing
> >>>> ctrl-C quits all the threads.  But if it is handling a request, the
> >>>> threads remain.  If I then press Stop in the browser, the threads
> >>>> still remain, and I have to kill them.  Whereas if I kill the
> >>>> threads
> >>>> with extreme prejudice, the browser suddenly times out.
> >>>>
> >>>> I'd expected the threads to just halt when I press ctrl-C and the
> >>>> browser to time out immediately.  But I haven't used a
> >>>> multithreaded
> >>>> framework for a while so I'm not sure this is possible.  Still, the
> >>>> main thread can tell the others to hurry up and exit, no?
> >>>
> >>> You can use a global variable that tells the other threads to exit
> >>> when they get around to it. I don't know of a way for the "main
> >>> thread" to "kill" the other threads.
> >>
> >> That's one thing I never understood.  Java does it, but Python claims
> >> it's impossible.
> >
> > Linux have pthread_kill(), but maybe it's too dependent on platform
> > and Python doesn't  support it.
> >
> > Java, AFAIR, does its own thread implementation.... but I may be
> > wrong.
> >
> > I'm also looking for a solution in this area :-(
>
> You're out of luck, there is not and never will be a solution to this
> "problem".
>
> It's simply not possible to safely kill a thread in Python without
> the consent of that thread, because it's not designed in a way that
> makes that a safe operation.  Java was designed with that constraint,
> but I'm sure that even Java fails to do this if the runaway thread is
> stuck in native code.
>
> Using pthread_kill would be very bad -- imagine that the killed
> thread was holding the GIL at the time.  Assuming the platform
> supported that function: you'd kill the thread, but you'd also
> deadlock Python because every other thread would wait forever on the
> GIL.
>
> IOTW, If you want killable execution contexts that don't require
> instrumentation, you must use processes.  You have no other option.

That was my guess... :-)

--
Gustavo Sverzut Barbieri
--------------------------------------
Computer Engineer 2001 - UNICAMP
Mobile: +55 (19) 9165 8010
 Phone:  +1 (347) 624 6296; [EMAIL PROTECTED]
Jabber: [EMAIL PROTECTED]
  ICQ#: 17249123
   MSN: [EMAIL PROTECTED]
   GPG: 0xB640E1A2 @ wwwkeys.pgp.net

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to