Skip to content
New issue

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

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

Already on GitHub? # to your account

Running async server no longer triggers events #884

Closed
furious-luke opened this issue Aug 9, 2017 · 2 comments
Closed

Running async server no longer triggers events #884

furious-luke opened this issue Aug 9, 2017 · 2 comments

Comments

@furious-luke
Copy link
Contributor

furious-luke commented Aug 9, 2017

Hi there, I've noticed that there has been a change somewhat recently whereby a server created via app.create_server now no longer triggers events. The source of the difference is here, in server.py:

    if run_async:
        return server_coroutine

    trigger_events(before_start, loop)

The serve function returns prior to triggering any events. Just wondering whether this was intended or not? And if so, why? I have some testing code I use that depended on running a server in the background and having the events triggered. I'm sure I can update it, but just wanted to confirm this is the intended behaviour.

Thanks!

Edit: If this is intended, would you be able to recommend the correct way to launch events for a background server?

@yunstanford
Copy link
Member

yunstanford commented Aug 9, 2017

It was a bug before, it would trigger before_start events twice when starting gunicorn worker. That's the reason we move the code.

Also, trigger_events(before_start, loop) is sort of sync way for triggering events. I am thinking when we start server asynchronously, we should also trigger events asynchronously.

User can easily do the triggering. But i can push a quick fix for that.

PS: app.create_server is not preferred to start Sanic app. For testing, we started Server and triggered all events asynchronously.

https://github.com/yunstanford/pytest-sanic/blob/master/pytest_sanic/utils.py#L17

@furious-luke
Copy link
Contributor Author

@yunstanford Thanks for the quick response! Please don't feel rushed, I've got a workaround that is easy enough for my case, so there's no rush.

I'm not using app.create_server for production usage, just for testing purposes. I've combined it with asynctest, seems to be working reasonably well at the moment.

Thanks again!

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

No branches or pull requests

3 participants