Skip to content

Worker interface #2928

@willmcgugan

Description

@willmcgugan

The work decorator possibly makes it too easy to create threads.

If you don't know what you are doing (and sometimes even if you do) threads can be a footgun. I think we should make launching threads more explicit.

I think the decorator should accept a thread argument which will create a thread worker if set to True.

Without thread=True it should be an error to decorate a non-coroutine.

i.e. the following should be an error:

@work
def foo(...):
    ...

To create a thread, it should be this:

@work(thread=True)
def foo(...):
    ...

This should create a thread worker:

@work
async def foo(...):
    ...

Note, this is a breaking change, which should be reflected in the CHANGELOG. It will also require an update to the docs.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions