Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Created March 25, 2018 08:54
Show Gist options
  • Save pfreixes/86df929da6c0d564f4cd23da6611d2d2 to your computer and use it in GitHub Desktop.
Save pfreixes/86df929da6c0d564f4cd23da6611d2d2 to your computer and use it in GitHub Desktop.
The id of different Asyncio tasks are the same due to the CPython memory implementation for objects smaller than X bytes
import asyncio
import sys
async def foo():
pass
async def test():
t = asyncio.tasks.create_task(foo())
print(sys.getsizeof(t))
print(id(t))
loop = asyncio.get_event_loop()
loop.run_until_complete(test())
loop.run_until_complete(test())
loop.run_until_complete(test())
@pfreixes
Copy link
Author

$ python3 test_allocator.py
160
4504608840
160
4504608840
160
4504608840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment