Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used without async/await? #173

Closed
roman-ku opened this issue Apr 11, 2017 · 5 comments
Closed

Can this be used without async/await? #173

roman-ku opened this issue Apr 11, 2017 · 5 comments

Comments

@roman-ku
Copy link

I tried removing the async/await and got this error:

with websockets.connect('...') as websocket:
AttributeError: __exit__
@roman-ku roman-ku changed the title Can this be used with async/await? Can this be used without async/await? Apr 11, 2017
@qwexvf
Copy link

qwexvf commented Apr 11, 2017

@roman-ku since it is based on asyncio you can't use without async/await....
why are you trying to remove them ?

Edit: i thought you was trying to use without coroutines features. sorry about misunderstood.

@aaugustin
Copy link
Member

Yes, you can use websockets without async / await. You'll have to use @asyncio.coroutine and yield from instead. This is generally less convenient than async / await. The only reason I can think of for doing that is if you're stuck on Python 3.3 (which is uncommon, since major distros ship 3.4)

If your question really was "can I use websockets in a synchronously", as @qwexvf correctly points out, websockets isn't a good choice for you. In that case, I suggest using another library, as websockets is a very small library whose sole purpose is to provide a convenient asynchronous API.

@roman-ku
Copy link
Author

@aaugustin @qwexvf

Yes my question was, can I use websockets synchronously. I need the response from the server before doing more stuff.

Alright thanks guys. I'll look for a different library.

@aaugustin aaugustin mentioned this issue Jun 23, 2019
18 tasks
@michaelschem
Copy link

Is there another library to use websockets synchronously?

@aaugustin
Copy link
Member

I'm not super familiar with the landscape of other libraries.

Since this issue was filed, I started working on a solution to this problem, see #885.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants