在以下代码dateTime.strptime()中,正在阻止asyncio.queue.get()操作
import time
import asyncio
from datetime import datetime
from functools import partial
def write(queue):
data = dict(fname = "Stack", lname = "Overflow")
# If you comment the below line thing are working fine
dob = datetime.strptime("2025-02-12", "%Y-%m-%d")
queue.put_nowait(data)
print("Writing to queue complete")
time.sleep(3600) # sleep forever
async def reader(queue):
loop = asyncio.get_running_loop()
print("This print means this thread is not blocked")
while msg := await queue.get():
print("Got my message", msg)
loop.call_soon(print, msg)
async def main():
queue = asyncio.Queue()
loop = asyncio.get_running_loop()
loop.run_in_executor(None, partial(write, queue))
await reader(queue)
asyncio.run(main())
如果我评论dateTime.strptime()函数调用,我将获得以下输出
Writing to queue complete
This print means this thread is not blocked
Got my message {'fname': 'Stack', 'lname': 'Overflow'}
{'fname': 'Stack', 'lname': 'Overflow'}
但如果未评论dateTime.strptime(),我将获得以下输出
This print means this thread is not blocked
Writing to queue complete
为什么dateTime.strptime()阻止asyncio.queue.get()操作?