Skip to content

How to handle exceptions ? #40

Open
@sumit-158

Description

@sumit-158

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Asyncer documentation, with the integrated search.
  • I already searched in Google "How to X in Asyncer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Asyncer but to AnyIO.
  • I already checked if it is not related to Asyncer but to Trio.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import asyncer
import logging
from typing import Union

from fastapi import FastAPI

async def func1(name: str):
    return {"message": f"Hello {name} form func1"}


async def func2():
    return {"message": f"Hello {name} form func2"}


@app.get("/test")
async def knowledge_panel(name_str: str):
    async with asyncer.create_task_group() as task_group:
        try:
            soon_value1 = task_group.soonify(func1)(name=name_str)
        except Exception:
            logging.exception()
        try:
            soon_value2 = task_group.soonify(func2)(name=name_str)
        except Exception:
            logging.exception()
    data = [soon_value1.value, soon_value2.value]
    return data

Description

  • How to handle an exception like here soon_value2 will throw an error, then how could I catch the exceptions and return user only single data rather than crashing the whole program?

Operating System

Windows

Operating System Details

No response

asyncer Version

0.0.1

Python Version

Python 3.10.5

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions