473,236 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

how do I stop SocketServer()?

supposing that I have a server (an instance of SocketServer()) that
waits for a connection (ie is blocked in accept()) and in another
thread i want to stop the server, how do I do that?
Aug 27 '08 #1
2 2019
Alexandru Mosoi wrote:
supposing that I have a server (an instance of SocketServer()) that
waits for a connection (ie is blocked in accept()) and in another
thread i want to stop the server, how do I do that?
By setting a timeout on the socket using socket.settimeout, and then
periodically check for an abortion condition in the server thread before
re-accepting connections.

Diez
Aug 27 '08 #2
On Wed, 27 Aug 2008 18:44:46 +0200, "Diez B. Roggisch"
<de***@nospam.web.dewrote:
>Alexandru Mosoi wrote:
>supposing that I have a server (an instance of SocketServer()) that
waits for a connection (ie is blocked in accept()) and in another
thread i want to stop the server, how do I do that?

By setting a timeout on the socket using socket.settimeout, and then
periodically check for an abortion condition in the server thread before
re-accepting connections.
You can also poll for activity by using the select() call. For
example:

...
local_host = '' # Symbolic name meaning the local host

server_port = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_port.bind((local_host, local_port))
server_port.listen(1)

readsocks = []
readsocks.append(sync_port)

# 'halt' would be your stop condition, set elsewhere
while halt == False:
readables, writeables, exceptions = select(readsocks, [], [], 1)

# does the socket has a connection pending?
if server_port in readables:
# process client connection
client_conn, client_addr = server_port.accept()
...
Aug 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
So I'm new to this python stuff - and this has me stumped # server import SocketServer PORT = 8037 class myRequestHandler(SocketServer.StreamRequestHandler): def handle(self): self.input...
3
by: Olivier Hoarau | last post by:
Hello, I have build a client/server application with the socket module. The server mades UDP broadcasting and the client only reads UDP broadcast messages. All work fine. Now I want to use for...
3
by: Ergin Aytac | last post by:
I'm trying to run a script written in python and have some socket connection problems. I cutted the origin script (more than 1000 lines) so it is only the part of the connection and there is no...
0
by: Adil Hasan | last post by:
Hello Fred, I just ran across your question. I think that the following code will work: ----- SERVER CODE ------ import SocketServer import time class...
5
by: missiplicity | last post by:
Hi, I am newbie to Python language and am taking my baby steps. I am using Python2.4 from ActiveState on W2K. I am trying to create a simple SocketServer program. Just adding the following 2 lines...
12
by: Paul Rubin | last post by:
Let's say you have a SocketServer with the threading mix-in and you run serve_forever on it. How can you shut it down, or rather, how can it even shut itself down? Even if you use a...
3
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server...
0
by: Tomi Hautakoski | last post by:
Hello, I'm a Python newbie trying to figure out how to use SocketServer with IPv6. I would like to set up a TCPServer working like below but how to tell SocketServer I need to use AF_INET6? ...
1
by: Okko Willeboordse | last post by:
Hello, SocketServer.ThreadingTCPServer accepts connections (clients can connect) before and after it's server_forever method is called, see below for an example. IMHO it should only accept...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.