Skip to content

asyncio.current_task() is None for asyncio.tasks._PyTask 3.14a6 #131709

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

Closed
graingert opened this issue Mar 25, 2025 · 7 comments
Closed

asyncio.current_task() is None for asyncio.tasks._PyTask 3.14a6 #131709

graingert opened this issue Mar 25, 2025 · 7 comments
Assignees
Labels
3.14 new features, bugs and security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Mar 25, 2025

Bug report

Bug description:

import asyncio

async def main():
    async def asyncfn():
        assert asyncio.current_task()

    t = asyncio.tasks._CTask(asyncfn())
    await t
    print("ctask worked")
    t = asyncio.tasks._PyTask(asyncfn())
    await t
    print("pytask worked")

asyncio.run(main())

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

@graingert graingert added the type-bug An unexpected behavior, bug, or error label Mar 25, 2025
@graingert graingert changed the title asyncio.current_task() is None for asyncio.tasks._PyTask (main branch only) asyncio.current_task() is None for asyncio.tasks._PyTask 3.14a6 Mar 25, 2025
@graingert
Copy link
Contributor Author

bisecting now

@graingert
Copy link
Contributor Author

introduced in 660f126

@graingert graingert added topic-asyncio 3.14 new features, bugs and security fixes labels Mar 25, 2025
@github-project-automation github-project-automation bot moved this to Todo in asyncio Mar 25, 2025
@kumaraditya303
Copy link
Contributor

Mixing pure python and C implementation is unsupported.

@graingert
Copy link
Contributor Author

all of the combinations are tested and supported

@unittest.skipUnless(hasattr(futures, '_CFuture') and
hasattr(tasks, '_CTask'),
'requires the C _asyncio module')
@add_subclass_tests
class CTask_CFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
Task = getattr(tasks, '_CTask', None)
Future = getattr(futures, '_CFuture', None)
all_tasks = getattr(tasks, '_c_all_tasks', None)
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
@unittest.skipUnless(hasattr(tasks, '_CTask'),
'requires the C _asyncio module')
@add_subclass_tests
class CTaskSubclass_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
Task = getattr(tasks, '_CTask', None)
Future = futures._PyFuture
all_tasks = getattr(tasks, '_c_all_tasks', None)
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
@add_subclass_tests
class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):
Future = getattr(futures, '_CFuture', None)
Task = tasks._PyTask
all_tasks = staticmethod(tasks._py_all_tasks)
current_task = staticmethod(tasks._py_current_task)
@unittest.skipUnless(hasattr(tasks, '_CTask'),
'requires the C _asyncio module')
class CTask_PyFuture_Tests(BaseTaskTests, test_utils.TestCase):
Task = getattr(tasks, '_CTask', None)
Future = futures._PyFuture
all_tasks = getattr(tasks, '_c_all_tasks', None)
current_task = staticmethod(getattr(tasks, '_c_current_task', None))
@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):
Task = tasks._PyTask
Future = getattr(futures, '_CFuture', None)
all_tasks = staticmethod(tasks._py_all_tasks)
current_task = staticmethod(tasks._py_current_task)
class PyTask_PyFuture_Tests(BaseTaskTests, SetMethodsTest,
test_utils.TestCase):
Task = tasks._PyTask
Future = futures._PyFuture
all_tasks = staticmethod(tasks._py_all_tasks)
current_task = staticmethod(tasks._py_current_task)
@add_subclass_tests
class PyTask_PyFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
Task = tasks._PyTask
Future = futures._PyFuture
all_tasks = staticmethod(tasks._py_all_tasks)
current_task = staticmethod(tasks._py_current_task)
@unittest.skipUnless(hasattr(tasks, '_CTask'),
'requires the C _asyncio module')
class CTask_Future_Tests(test_utils.TestCase):

@kumaraditya303
Copy link
Contributor

If you are creating a pure python task then you need to call the pure python version of current_task i.e. asyncio.tasks._py_current_task

@graingert
Copy link
Contributor Author

ah I see ok

@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Mar 25, 2025
@graingert
Copy link
Contributor Author

there's definitely code out there that switches the task to PyTask using the task factory - this could do with a note in the changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

2 participants