python / asyncio

asyncio historical repository
https://docs.python.org/3/library/asyncio.html
1.04k stars 177 forks source link

Why asyncio does not raise up exection when using `logging.config.fileConfig` #424

Closed ahuigo closed 7 years ago

ahuigo commented 7 years ago

Why asyncio does not raise up exception when using logging.config.fileConfig.

Here is an example.

# python >= 3.5.0

import asyncio
import time
from os.path import exists

import logging
import logging.config

conf = '''
[loggers]
keys=root

[logger_root]
level=DEBUG
handlers=hand01

[handlers]
keys=hand01

[handler_hand01]
class=StreamHandler
args=(sys.stdout,)
formatter=form01

[formatters]
keys=form01

[formatter_form01]
format=%(asctime)s %(filename)s +%(lineno)d %(levelname)s %(message)s
datefmt=%a, %d %b %Y %H:%M:%S

'''

if not exists('log.conf'):
    open('log.conf', 'w').write(conf)
    print('Initialize log.conf.....')
    quit('Try again please.');

logging.config.fileConfig("log.conf")

async def sync():
    print("No exception raise ");
    t=undefined.func()
    print("Not work");

asyncio.get_event_loop().run_until_complete(asyncio.wait([sync()]))
Martiusweb commented 7 years ago

Hi,

I'm not sure I understand your problem, but it doesn't look like it's a bug in asyncio.

wait() is a helper which allows to wait on several tasks (or future) at once, it will not raise th exceptions happening in the task. In your case, if you want the exception to raise, don't use asyncio.wait(): https://docs.python.org/3/library/asyncio-task.html#asyncio.wait.

If you have a question about how asyncio works, I suggest that you start a thread on the users mailing list, which is probably a better place to discuss than the github bug tracker: https://groups.google.com/forum/#!forum/python-tulip

ahuigo commented 7 years ago

In fact , it will raise exceptions happening in the task when there is no logging.config.fileConfig.