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

CancelledError does not cancel 'mode.Worker' #51

Open
2 tasks done
nikitagashkov opened this issue Dec 5, 2019 · 2 comments
Open
2 tasks done

CancelledError does not cancel 'mode.Worker' #51

nikitagashkov opened this issue Dec 5, 2019 · 2 comments

Comments

@nikitagashkov
Copy link

Checklist

  • I have included information about relevant versions
  • I have verified that the issue persists when using the master branch of Mode.

Steps to reproduce

Have a Service with a canceled background task wrapped into Worker:

class Api(mode.Service):
    @mode.Service.task
    def main(self) -> None:
        raise asyncio.CancelledError()

if __name__ == '__main__':
    mode.Worker(Api()).execute_from_command_line()

Expected behavior

A task's CancelledError can be propagated to the worker.

Actual behavior

An application seems stuck and unresponsive.

Full traceback

Paste the full traceback (if there is any)

Versions

  • Python version: 3.7.5
  • Mode version: 4.1.2
  • Operating system: Debian-based official Python 3.7 image
@nikitagashkov
Copy link
Author

Also, is there a way to stop the worker upon request? Right now, I traverse through a beacon to find the worker and schedule its shutdown, but is there a better way?

asyncio.ensure_future(self.beacon.root.data.stop())

Thanks!

@ask
Copy link
Owner

ask commented Dec 12, 2019

The program above raising CancelledError works for me, it pretty much just exits (mode master)

I agree using the beacon to stop is not very great, I guess the best way is if you have a reference
to the worker already.

You can stop the worker, but you can also stop the service passed to Worker(): that's what we do in Faust. We have an App class that starts all the services needed, and call app.stop() to stop the worker (the app is also passed pretty much everywhere, if you don't like passing you could use dependency injection or a Local (mode.locals).

Also... there's always raise SystemExit() :)

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

2 participants