How do I abort a socket.recv() from another thread in Python

后端 未结 4 1945
野性不改
野性不改 2021-02-01 22:22

I have a main thread that waits for connection. It spawns client threads that will echo the response from the client (telnet in this case). But say that I want to close down all

4条回答
  •  执念已碎
    2021-02-01 23:06

    I know this is an old thread and that Samuel probably fixed his issue a long time ago. However, I had the same problem and came across this post while google'ing. Found a solution and think it is worthwhile to add.

    You can use the shutdown method on the socket class. It can prevent further sends, receives or both.

    socket.shutdown(socket.SHUT_WR)

    The above prevents future sends, as an example.

    See Python docs for more info.

提交回复
热议问题