Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • Latest Bullseye images break Websockets

$
0
0
Pi 4. Running the following server.py code on existing Bullseye SD cards with Python 3.9.2 or on new Bookworm SD cards with Python 3.11.x works fine but if a new SD card is burned using Raspberry Pi imager for either of the 64 bit versions with desktop the program crashes as shown below. This seems to have started within the last few days.

Code:

import asyncioimport websocketsprint("Starting")async def handler(websocket, path):    data = await websocket.recv()    reply = f"Data recieved as:  {data}!"    await websocket.send(reply)start_server = websockets.serve(handler, "localhost", 8088)asyncio.get_event_loop().run_until_complete(start_server)asyncio.get_event_loop().run_forever()

Normal result is to just print 'Starting' and then it waits for connection. On latest Bullseye 64 bit desktop images for Pi4 results in the following

pi@raspberrypi:~ $ python server.py
Starting
Traceback (most recent call last):
File "/home/pi/server.py", line 13, in <module>
start_server = websockets.serve(handler, "localhost", 8088)
File "/home/pi/.local/lib/python3.9/site-packages/websockets/asyncio/server.py", line 736, in __init__
self.server = Server(
File "/home/pi/.local/lib/python3.9/site-packages/websockets/asyncio/server.py", line 281, in __init__
self.loop = asyncio.get_running_loop()
RuntimeError: no running event loop

So the error is 'no running event loop'

Statistics: Posted by mercedes1954 — Sun Nov 10, 2024 12:19 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles