0

EDIT: Looks like I found the solution here: Python SocketServer

I am testing it now to make sure it does what I am looking for. I will leave the question open for now to hear other approaches.

End Edit

I am developing a client-server system in Python.

There are multiple clients, in tens of thousands. The server will need to accept connections, receive data and process the data.

I have this part done and its working fine.

Once the server determines that all the clients sent in their data, the http server needs to shutdown, print the processed data and exit.

I am using pyjsonrpc (https://pypi.python.org/pypi/python-jsonrpc/0.3.4) to move data from client to the server.

I am using the http server example code from the above page. I am unable to figure out how to exit on demand from "http_server.serve_forever()" statement. I found some similar questions on stackoverflow but didnt help me much.

If I missed a previously answered question, please point me to it.

Thank you

Community
  • 1
  • 1
powerrox
  • 1,314
  • 11
  • 21
  • Do you need to shutdown it by request from socket? Or you want to send signal/press Ctrl+C? How should it be? You have found good solution for your case. You should `stop` processing of new connections(set a flag to ignore new connections) and wait other(last?) connection to die. – dt0xff Jun 26 '14 at 18:49
  • do `server.shutdown()` -- https://docs.python.org/dev/library/socketserver.html#socketserver.BaseServer.shutdown – johntellsall Jun 26 '14 at 20:52

0 Answers0