On Thu, 20 Jun 2019 at 16:33, Guido van Rossum <gu...@python.org> wrote:

> On Thu, Jun 20, 2019 at 8:21 AM Michael Foord <fuzzy...@gmail.com> wrote:
> > It works by raising an exception in the target thread, which the thread
> is free to handle (usually for cleanup and then reraise).
>
> Sure, those are the right semantics. How does it stop blocking I/O though?
> Suppose the thread is waiting for a server to return a response which just
> isn't ever going to come, but the connection somehow is kept open by the
> other side?
>



Sorry, resending to list as well.



It used to be on the CLR getting back control. So it couldn't handle that
case. (.NET 1.1).

https://jonskeet.uk/csharp/threads/abort.html

It has since been improved. It still blocks on the execution of unmanaged
code (or computation in a finally block handling the ThreadAbortException),
but blocking IO can be interrupted:

https://docs.microsoft.com/en-us/dotnet/api/system.threading.thread.abort?view=netframework-4.8

If Abort is called on a thread that is blocked or is sleeping, the thread
is interrupted and then aborted.

This SO question on the topic says:

https://stackoverflow.com/questions/365370/proper-way-to-stop-tcplistener


Thread.Abort()

There are 2 things I see you could do. 1 is that if you have started this
TcpListener thread from another you can simply call Thread.Abort instance
method on the thread which will cause a threadabortexception to be thrown
within the blocking call and walk up the stack.

Michael


>
> --
> --Guido van Rossum (python.org/~guido)
> Pronouns: he/him/his (why is my pronoun here?)
>
-- 

Michael Foord

Python Consultant, Contractor and Trainer

https://agileabstractions.com/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ARIZ3WMWXIP6MICQFW3OKE4VY43OKXEK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to