Skip to content

User Created Event Loop Not Logging #602

@maiqbal11

Description

@maiqbal11

When the user creates an event loop and runs their function code in it, logs are not generated for functions called within the event loop.

For example, the following code would not log the line Python timer trigger function ran at ...:

import datetime
import logging
import asyncio

import azure.functions as func


async def log_timer_triggered():
    asyncio.sleep(1)
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

def main(mytimer: func.TimerRequest) -> None:
    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('main')
    loop = asyncio.SelectorEventLoop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(log_timer_triggered())
    loop.close()
    logging.info('main done')

However, the following will work fine and logs will be present:

async def log_timer_triggered():
    asyncio.sleep(1)
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

def main(mytimer: func.TimerRequest) -> None:
    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('main')
    await log_timer_triggered()
    logging.info('main done')

The former is an async pattern that we do not currently handle as we expect users to run within the loop that we provide. Possible solutions would include either (a) handling user provided event loops or (b) surfacing warnings after detecting this pattern.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions