我正在使用标准 Python 日志库 ( import logging
) 并安装 Ideolog 插件。但它不支持标准日志库的格式(并且 PyCharm 要求对其进行配置)。我尝试了一些正则表达式,但它们不适合。我应该如何配置它?
PS在代码中我使用日志记录 logging.info('Some info')
我使用这个答案中的代码,但是asyncio.exceptions.CancelledError
当队列为空时得到。在实际项目中,我将任务添加到消费者的队列中,这就是我使用while True
语句的原因
我压缩该代码以使调试更容易:
import asyncio
import traceback
async def consumer(queue: asyncio.Queue):
try:
while True:
number = await queue.get() # here is exception
queue.task_done()
print(f'consumed {number}')
except BaseException:
traceback.print_exc()
async def main():
queue = asyncio.Queue()
for i in range(3):
await queue.put(i)
consumers = [asyncio.create_task(consumer(queue)) for _ in range(1)]
await queue.join()
for c in consumers:
c.cancel()
asyncio.run(main())
Run Code Online (Sandbox Code Playgroud)
和错误:
consumed 0
consumed 1
consumed 2
Traceback (most recent call last):
File "/Users/abionics/Downloads/BaseAsyncScraper/ttt.py", line 8, in consumer
number …
Run Code Online (Sandbox Code Playgroud)