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

fix typo in Asyncio example #1510

Merged
merged 2 commits into from
Mar 15, 2019
Merged

fix typo in Asyncio example #1510

merged 2 commits into from
Mar 15, 2019

Conversation

sam-writer
Copy link
Contributor

No description provided.

@sam-writer
Copy link
Contributor Author

On a related note, when trying to run this on Python 3.7.1, Sanic 18.12.0, I get an error when doing

 srv_coro = app.create_server(
        sock=sock,
        return_asyncio_server=True,
        asyncio_server_args=dict(
            start_serving=False
        )
    )
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-114731fc73ad> in <module>
      4     return_asyncio_server=True,
      5     asyncio_server_args=dict(
----> 6         start_serving=False
      7     )
      8 )

TypeError: create_server() got an unexpected keyword argument 'return_asyncio_server'

@vltr
Copy link
Member

vltr commented Mar 12, 2019

@sam-qordoba this error is due to a change on Sanic that is scheduled to be released with version 19.03 ... Are you sure you're running 18.12 from PyPI?

EDIT: yes, this error should be thrown if using version 18.12 because these changes will only work with Sanic 19.03 onwards.

ahopkins
ahopkins previously approved these changes Mar 12, 2019
@sam-writer
Copy link
Contributor Author

sam-writer commented Mar 12, 2019

EDIT: yes, this error should be thrown if using version 18.12 because these changes will only work with Sanic 19.03 onwards.

I see, that is why pip installing directly from GitHub fixed the issue. Also, even when installing with SANIC_NO_UVLOOP=true, on macOS I am still getting a uvloop instance. Is there a way to force the use of a different event loop? I assume it is because I am running uvloop that I get this error


In [25]:     loop = asyncio.get_event_loop()
    ...:     srv_coro = app.create_server(
    ...:         sock=sock,
    ...:         return_asyncio_server=True,
    ...:
    ...:     )

In [26]: srv = loop.run_until_complete(srv_coro)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-26-52d4d20c1609> in <module>
----> 1 srv = loop.run_until_complete(srv_coro)

/anaconda3/lib/python3.7/site-packages/uvloop/loop.pyx in uvloop.loop.Loop.run_until_complete()

/anaconda3/lib/python3.7/site-packages/sanic/app.py in create_server(self, host, port, debug, ssl, sock, protocol, backlog, stop_event, access_log, return_asyncio_server, asyncio_server_kwargs)
   1207
   1208         return await serve(
-> 1209             asyncio_server_kwargs=asyncio_server_kwargs, **server_settings
   1210         )
   1211

/anaconda3/lib/python3.7/site-packages/uvloop/loop.pyx in create_server()

/anaconda3/lib/python3.7/site-packages/uvloop/loop.pyx in create_unix_server()

OSError: [Errno 9] Bad file descriptor

@vltr
Copy link
Member

vltr commented Mar 12, 2019

Also, even when installing with SANIC_NO_UVLOOP=true, on macOS I am still getting a uvloop instance.

That's strange. I think you should open a new issue related to this if you installed using pip. If you used conda, then Idk, probably file an issue anyway so we can redirect to the proper place.

Is there a way to force the use of a different event loop?

Well, if you don't want uvloop, all you need to do is uninstall it:

pip uninstall uvloop

And it'll probably use the Python default loop implementation 😉

@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

Merging #1510 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1510   +/-   ##
=======================================
  Coverage   91.35%   91.35%           
=======================================
  Files          18       18           
  Lines        1781     1781           
  Branches      337      337           
=======================================
  Hits         1627     1627           
  Misses        130      130           
  Partials       24       24

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d581315...3f88d4a. Read the comment docs.

@yunstanford
Copy link
Member

@vltr pip enables wheel install by default, which is bdist (built dist). it doesn't run setup.py.

You can disable binary install.

@sam-writer
Copy link
Contributor Author

@vltr I used a virtualenv and that worked. For the example to work, you need to make sure uvloop isn't installed or it will be used automatically, and fail.

@vltr
Copy link
Member

vltr commented Mar 12, 2019

@yunstanford you're right, I forgot that "simple" detail ... So, how would we install Sanic without uvloop using pip? Sorry for asking, my mind has been bleeding through my ears lately ...

@vltr
Copy link
Member

vltr commented Mar 12, 2019

@sam-qordoba I think uvloop should work on BSD based systems (but I might be wrong). Try to run a simple asyncio server with uvloop enabled to see if it works - like an echo server.

@sam-writer
Copy link
Contributor Author

Sorry, I am confused. Sanic does indeed work with uvloop in general, but for this fancy Asyncio demo, it does not.

For reference, I am trying to figure out how to have a server which exposes a REST API, but doesn't block, so that it can also connect to Google PubSub via the SDK

@vltr
Copy link
Member

vltr commented Mar 12, 2019

@sam-qordoba oh, ok. Do you mind on bringing that question to the community forums ? It's easier to follow there 😄

@sjsadowski
Copy link
Contributor

sjsadowski commented Mar 14, 2019

lint runtests: commands[2] | isort --check-only --recursive sanic
ERROR: /home/travis/build/huge-success/sanic/sanic/testing.py Imports are incorrectly sorted.
ERROR: InvocationError for command '/home/travis/build/huge-success/sanic/.tox/lint/bin/isort --check-only --recursive sanic' (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   lint: commands failed

We need to identify the actual issue and fix it so this can get merged.

@sam-writer
Copy link
Contributor Author

@sjsadowski - do you need anything from me?

@sjsadowski
Copy link
Contributor

@sam-qordoba nope, this was fixed with another PR. Thanks.

@sjsadowski sjsadowski merged commit abf8534 into sanic-org:master Mar 15, 2019
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

Successfully merging this pull request may close these issues.

None yet

5 participants