1

I am trying to live-stream using a server and the code after serve_forever() is not running. I am not able to stop live-streaming without using the keyboard interrupt. I need to use python code for stopping the live-stream after a certain time, closing the server and closing the raspberry pi camera. Any help would be appreciated.

try: 
    address = ('',8000)
    server = StreamingServer(address, StreamingHandler)
    server.serve_forever()
finally:
    camera.stop_recording()
  • 3
    I don't know the library you are using but suspect you don't want to use `serve_forever()` if you don't want to serve forever. What other methods are available on a `StreamingServer` object? – T Burgis Mar 14 '19 at 09:36
  • 2
    one way to do it is use `signals` have a signal handler call `server_close()` when triggered – Nullman Mar 14 '19 at 09:38
  • [here](https://stackoverflow.com/questions/268629/how-to-stop-basehttpserver-serve-forever-in-a-basehttprequesthandler-subclass) is a similar question, im not sure what kind of server you are using, but this might be what you are looking for – Nullman Mar 14 '19 at 09:43

1 Answers1

0

The normal method is to call server.shutdown(). Simply it cannot be called from the request handler. Long story short: call it from a different thread.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252