Add API to name background tasks
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
Description
asyncio.create_task() from the standard library allows for identifying tasks with names. This seems particularly handy in case where you want to know about the status of a background task in Quart context and I think it'd be a nice feature to support. In the app that I'm currently working on, I'm using the background task to run an MQTT listener and logger, which can be configured via HTTP/GraphQL.
To ensure compatibility, I'd propose a check for 'name' in the kwargs and passing that to the task creation LOC
An example of how'd I'd like to be able to use this feature:
# called inside @app.before_serving
async def mqtt_handler():
broker_url = env.str("MQTT_BROKER_HOST", "localhost")
broker_port = env.int("MQTT_BROKER_PORT", 1883)
mqtt_logger = MQTTLogger(app.db, broker_url, broker_port)
app.add_background_task(mqtt_logger.start, name="MQTTLoggerTask")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/quart/app.py at the app.add_background_task implementation around the linked lines, and compare its task creation with asyncio.create_task(). Support an optional name argument while preserving existing calls without it; done means the background-task API accepts the example usage and passes the name through.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100