aioify is a good library for sync function, Can I interrupt my sleep function with cancel?
wuranxu opened this issue · 1 comments
wuranxu commented
import time
import asyncio
from aioify import aioify
@aioify
def long_time_task():
print("I'm going to sleep 12 second")
time.sleep(12)
print("I have slept 12 second")
async def main():
task = asyncio.create_task(long_time_task())
await asyncio.sleep(2)
task.cancel()
try:
await task
except asyncio.CancelledError:
print("The task has been canceled")
if __name__ == "__main__":
asyncio.run(main())
That's my code, But I don't known why the task is still alive, and what can I do to make it work well.
I'd like to run a long time task, so I use time.sleep to make task run a long time.
When I make it async, it doesn't work as my expectd.
😭
rominf commented
Hi. Sorry for the very long delay. I've put the library into maintenance mode (see reasons and proper ways to do similar things in README.md).