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
Clean up loop handling #381
Comments
Let's also talk about testing in that context. I find it really hard to test a Sanic app. My current blocker is a I'm using pytest_async with quite some success, but here it doesn't help. By the way, you can observe the same failure with current master. Let us try to find a good way for testing (API tests and unit tests) and document that. Any suggestions? |
Yeah I'm observing the failure right now, I'm going to roll back the commit that cause it. |
Fixed the RuntimeError with 487e335 |
No I understand the confusion, I think it stems from us trying to solve #275, but I don't think there's enough of a use-case to actually have a non-blocking way to run the server. |
What I liked about the commit was |
I have an idea for how to handle the loop policy / loop sharing, I'll post it up in another commit but needless to say it'll involve addressing concerns over us messing with asyncio global settings (Which I'm not a fan of anyway.) I'll have the PR up later this week. |
Things are definitely a mess. This is what happens for me when I run the simple_server.py example with debug set to
Note that I'm not passing a loop, but I still get the deprecation warning (because |
Both issues go away when I stop passing the loop from |
I can confirm
if i just remove the |
@lvalladares Why would you need to use the loop after running |
@seemethere im using I think the use case can be any async cleanup operation after the test. |
@lvalladares does it work to get a new event loop afterwards and run it there? For example: class WidgettestCase(unittest.TestCase):
app = Sanic()
def tearDown(self):
loop = asyncio.new_event_loop()
loop.run_until_complete(db.archivos.delete())
def test_sanic(self):
@app.route('/')
def hello(request):
return text('ok')
req, res = app.test_client.get('/')
assert res.body == b'ok' |
What about use cases where I want to create sth via the API and then also read it? That's a pretty simple case. |
@r0fls nop, doesnt work, i get the following error:
i workaround it making all my calls on tearDown sync but this is very hard with some packages. |
Closing. I think we took care of most of the concerns here. Will re-open if necessary. |
Lately, there have been some changes regarding the loop which resulted in kind of a messy situation. I'd suggest, instead of making a bunch of small uncoordinated changes, let's discuss how we'd actually want to have it.
The issues I see are
app.run()
accepts aloop
parameter which it says will be deprecated in 0.4.0, however, it already ignores that parameter now. Let's either completely remove it or if we accept it, it should do something.app.run()
takes the default loop (via_helper
) and passes it toserve()
. Hence, the code creating a loop inserve()
will never execute.While we're at it, we should fix
_helper
and it's usages. Some params are not used, another is misspelled.I'd be happy to provide a PR, but let's agree on a bearing way first.
The text was updated successfully, but these errors were encountered: