circuitpython/tests/extmod/asyncio_task_hash.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
759 B
Python
Raw Normal View History

# Test hash unary operator for a Task
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task():
pass
async def main():
# Confirm that the hash is an int
print("=" * 10)
t1 = asyncio.create_task(task())
t2 = asyncio.create_task(task())
print(type(hash(t2)))
print(type(hash(t1)))
# Check that two tasks don't have the same hash
print("=" * 10)
t1 = asyncio.create_task(task())
t2 = asyncio.create_task(task())
print(hash(t1) != hash(t2))
# Add tasks to a set
print("=" * 10)
t1 = asyncio.create_task(task())
t2 = asyncio.create_task(task())
tasks = set()
tasks.add(t1)
print(t1 in tasks)
print(t2 in tasks)
asyncio.run(main())