小编Abi*_*ics的帖子

Ideolog (PyCharm):如何为标准日志库配置日志格式

我正在使用标准 Python 日志库 ( import logging) 并安装 Ideolog 插件。但它不支持标准日志库的格式(并且 PyCharm 要求对其进行配置)。我尝试了一些正则表达式,但它们不适合。我应该如何配置它?

日志格式和 Ideolog 错误的屏幕

默认 Ideolog 设置

PS在代码中我使用日志记录 logging.info('Some info')

logging pycharm

9
推荐指数
3
解决办法
5255
查看次数

Python CancelledError 与 asyncio 队列

我使用这个答案中的代码,但是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)

python queue producer-consumer python-asyncio

0
推荐指数
1
解决办法
3925
查看次数