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

asyncio.all_tasks() should return only non-finished tasks. #76791

Closed
asvetlov opened this issue Jan 21, 2018 · 7 comments
Closed

asyncio.all_tasks() should return only non-finished tasks. #76791

asvetlov opened this issue Jan 21, 2018 · 7 comments
Labels

Comments

@asvetlov
Copy link
Contributor

BPO 32610
Nosy @asvetlov, @1st1, @miss-islington
PRs
  • bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. #7174
  • [3.7] bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174) #7181
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-05-29.15:16:15.087>
    created_at = <Date 2018-01-21.16:45:25.597>
    labels = ['release-blocker', '3.8', 'expert-asyncio']
    title = 'asyncio.all_tasks() should return only non-finished tasks.'
    updated_at = <Date 2018-05-29.15:16:15.086>
    user = 'https://github.com/asvetlov'

    bugs.python.org fields:

    activity = <Date 2018-05-29.15:16:15.086>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-29.15:16:15.087>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2018-01-21.16:45:25.597>
    creator = 'asvetlov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32610
    keywords = ['patch']
    message_count = 7.0
    messages = ['310378', '310379', '312907', '317921', '317927', '317928', '317963']
    nosy_count = 3.0
    nosy_names = ['asvetlov', 'yselivanov', 'miss-islington']
    pr_nums = ['7174', '7181']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32610'
    versions = ['Python 3.8']

    @asvetlov
    Copy link
    Contributor Author

    Current behavior has a subtle pitfall.
    The function returns a list of *existing* tasks (not removed by decref or explicit call).
    If user's code has a strong reference to some task the task will be in return list for unpredictable amount of time, even if the task was done.

    Returning only alive tasks can make a function result more predictable (not task.done()).

    Opinions?

    @1st1
    Copy link
    Member

    1st1 commented Jan 21, 2018

    I agree, returning done tasks is pretty useless.

    This is a new function so let's fix its behavour. We need to:

    1. Document this difference between new asyncio.all_tasks() and now deprecated Task.all_tasks().

    2. Make sure that Task.all_tasks() works in 3.7 in the same way it was working before 3.7.

    @asvetlov
    Copy link
    Contributor Author

    After re-thinking I come to another idea: let's keep all_tasks() behavior as is but add an active_tasks() function for returning all non-finished tasks.

    It should be done in Python 3.8

    @asvetlov asvetlov added 3.8 only security fixes and removed 3.7 (EOL) end of life labels Feb 26, 2018
    @1st1
    Copy link
    Member

    1st1 commented May 28, 2018

    After an off-list discussion I think I was able to convince Andrew to change the behaviour of the newly added asyncio.all_tasks() to return only pending tasks. The logic behind this is that:

    1. there's no good known use case for returning a list of all non-GC-ed tasks; if such a case exists, it's easy to implement support for it via 'loop.set_task_factory'.

    2. OTOH, whenever one uses Task.all_task() they always want to filter out completed tasks.

    3. Since this is a new API, it makes sense to design it right and not strive for backwards compatibility with now deprecated asyncio.Task.all_tasks().

    @1st1
    Copy link
    Member

    1st1 commented May 28, 2018

    New changeset 416c1eb by Yury Selivanov in branch 'master':
    bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174)
    416c1eb

    @1st1
    Copy link
    Member

    1st1 commented May 28, 2018

    Ned, this one would also be nice to have in 3.7.0. The patch alters the behaviour of new 3.7 api.

    @miss-islington
    Copy link
    Contributor

    New changeset ddc613f by Miss Islington (bot) in branch '3.7':
    bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174)
    ddc613f

    @1st1 1st1 closed this as completed May 29, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants