Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asyncio websocket Send with No Prefix

All asyncio and websocket documentation I have read states that packets must be sent using the await (or yield from) prefix syntax. I would like to be able to call a function to send, however, without such syntax. Is it possible to use such syntax?

Existing:

await websocket.send(message)

Desired:

websocket.send(message)
like image 669
2Cubed Avatar asked Mar 15 '26 19:03

2Cubed


1 Answers

No, asynchronous code wouldn't work without await/yield from statement. That's how asynchrony in Python organized and there were reasons to do it.

You can use synchronous websocket client instead, but I don't advise you to do it: asynchronous app would work faster.

asyncio syntax might look uncomfortable at first sight, but when you'll practice a bit, you'll see that it only helps you.

like image 54
Mikhail Gerasimov Avatar answered Mar 18 '26 09:03

Mikhail Gerasimov