Skip to content

Custom exception handler in anyio #573

Answered by smurfix
deivydaslipskis asked this question in Q&A
Discussion options

You must be logged in to vote

When changing to anyio I don't know how I can set my custom exception handler, how could I do that?

You don't. Structured Concurrency means that there's no need for installing a global exception handler.

async def main_proc(task_manager: "TaskManager") -> None:
    try:
        async with anyio.create_task_group() as task_group:
            task_group.start_soon(process, task_manager)
    except TaskDone:
        logger.info("Task is completed, finishing...")
    except Exception as err:  # you should never catch a BaseException without re-raising it
            logger.error(err, exc_info=True)

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@deivydaslipskis
Comment options

Answer selected by deivydaslipskis
Comment options

You must be logged in to vote
3 replies
@deivydaslipskis
Comment options

@smurfix
Comment options

@deivydaslipskis
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants