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

Add name param to spawn #324

Closed
dave-fitzgerald-bc opened this issue May 6, 2022 · 2 comments · Fixed by #385
Closed

Add name param to spawn #324

dave-fitzgerald-bc opened this issue May 6, 2022 · 2 comments · Fixed by #385

Comments

@dave-fitzgerald-bc
Copy link

dave-fitzgerald-bc commented May 6, 2022

Feature request:

I would like to be able to use the scheduler API to set and get task/job names. Something like so:

Proposed Usage

await scheduler.spawn(my_task(), name="my-task")
await scheduler.spawn(another_task(), name="another-task")

jobs = [job for job in scheduler._jobs]
task_names = [job._task.get_name() for job in jobs]

Output:

task_names
> ['my-task', 'another-task']

Bonus Usage

Even better would be delegating job.get_name() to job._task.get_name() so the final usage could be like:

job_names = [job.get_name() for job in scheduler._jobs]

Output:

job_names
> ['my-task', 'another-task']

At the moment if I needed to get the task name I would have to use the following and I'd rather not access so many private variables if possible:

task_names = [job._coro.cr_code.co_name for job in scheduler._jobs]
@Dreamsorcerer
Copy link
Member

I think we could pass the name parameter to asyncio.create_task() somehow and then maybe add a helper method to also fetch the name.

Feel free to make a PR.

@dave-fitzgerald-bc
Copy link
Author

Thanks @Dreamsorcerer & @zoicsoftware for your time and effort

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

Successfully merging a pull request may close this issue.

2 participants