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

Using curio in sanic controller #651

Closed
briskly opened this issue Apr 18, 2017 · 2 comments
Closed

Using curio in sanic controller #651

briskly opened this issue Apr 18, 2017 · 2 comments

Comments

@briskly
Copy link

briskly commented Apr 18, 2017

I wanted to use async raw socket in my sanic application on Python 3.6 And was really surprised that async functions from curio doesn't work in sanic async context. Minimal proof of concept:

import curio
from sanic import Sanic
from sanic.response import text
app = Sanic(__name__)


@app.route('/')
async def index(request):
    sock = await curio.open_connection("google.com", 443, ssl=True)
    resp = await sock.recv(1024)
    return text(resp)


app.run(host="0.0.0.0", port=5001)

This code generates core dump on any http request

$ python3 test2.py 
2017-04-17 17:33:13,266: INFO: Goin' Fast @ http://0.0.0.0:5001
2017-04-17 17:33:13,270: INFO: Starting worker [93060]
Fatal Python error: GC object already tracked

Current thread 0x00007fc57706e480 (most recent call first):
  File "/usr/lib/python3.6/linecache.py", line 165 in lazycache
  File "/usr/lib/python3.6/traceback.py", line 345 in extract
  File "/usr/lib/python3.6/traceback.py", line 497 in __init__
  File "/usr/lib/python3.6/traceback.py", line 117 in format_exception
  File "/usr/lib/python3.6/traceback.py", line 163 in format_exc
  File "/usr/lib/python3.6/site-packages/sanic/handlers.py", line 93 in default
  File "/usr/lib/python3.6/site-packages/sanic/handlers.py", line 70 in response
  File "/usr/lib/python3.6/site-packages/sanic/app.py", line 472 in handle_request
  File "/usr/lib/python3.6/site-packages/sanic/server.py", line 410 in serve
  File "/usr/lib/python3.6/site-packages/sanic/app.py", line 561 in run
  File "test2.py", line 14 in <module>
Aborted (core dumped)

Am I doing something wrong?

@Sniedes722
Copy link
Contributor

From the official Curio docs:
"Curio can also submit work to the asyncio event loop with the provision that it must be running separately in a different thread."

Look at this issue

Curio's main implementation of events is a queue, not an event loop. You're trying to spawn tasks inside the same thread Sanic (and the event loop) are running from.

@seemethere
Copy link
Member

Yeah there's no real way of using curio alongside asyncio right now (not that I particularly know of)

Closing this because it's not really related to sanic but rather asyncio vs. curio

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

3 participants