Hi,
I'm having issues with "except KeyboardInterrupt" in the following code
It brings up an error when run as shown in the second code block. Ant help would be great. Thanks M
Debug give the following code error
I'm having issues with "except KeyboardInterrupt" in the following code
It brings up an error when run as shown in the second code block. Ant help would be great. Thanks M
Code:
import socketimport timefrom picamera2 import picamera2from picamera2.encoders import H264Encoderfrom picamera2.outputs import FileOutput#Configure the cameracam=Picamera2()vid_config=cam.create_video_configuration({"size":(1280,720)})cam.configure(vid_config)encoder=H264Encoder(1000000)cam.encoders=encoder#Listen on a socket for a connectionwith socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(("192.168.0.220",8888)) sock.listen() #Each time through the loop, stream vide until the #client disconnects try: while True: conn, addr=sock.accept() stream=conn.makefile("wb") encoder.output=FileOutput(stream) cam.start_encoder(encoder) cam.start #Wait until the client disconnects try: while(conn.recv(512)): pass except ConnectionsResetError: pass print("Client disconnected.") cam.stop() cam.stop_encoder() conn.close()except KeyboardInterrupt: #Press CTRL+C to quit. print("Received CTRL+C, exiting.") sock.close()
Code:
except KeyboardInterrupt:SyntaxError: expected 'except' or 'finally' block
Statistics: Posted by MartinJames — Thu Dec 19, 2024 1:55 pm