3

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)
2Cubed
  • 3,401
  • 7
  • 23
  • 40

1 Answers1

4

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.

Community
  • 1
  • 1
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159