# use\_routine\_dispatcher 函数

## 简介

为当前无服务器云函数使用例程派发器框架。

```python
def use_routine_dispatcher(
    override_handler: bool = True
) -> IntegrateDispatch
```

当该函数的参数 `override_handler` 被忽略或值设置为 `True` 时，该函数将尝试查找本次函数调用是由哪一个 Python 模块发起，并在来源 Python 模块中创建或覆盖名为 `main` 的无服务器云函数执行方法。

{% hint style="info" %}
请注意，请确保当前无服务器云函数的执行方法名为 main，并且仅在包含执行方法定义的 Python 模块中调用一次该函数，否则该函数可能无法正常工作。
{% endhint %}

如果您的无服务器云函数已确定使用适用于无服务器云函数集成调用的例程派发器框架，您将无需为该无服务器云函数编写名为 `main` 的执行方法。

## 参数

该函数拥有的参数、参数类型和参数描述如下：

| 参数                | 类型   | 必选 | 描述                                  |
| ----------------- | ---- | -- | ----------------------------------- |
| override\_handler | bool | 否  | 是否创建或覆盖调用该函数的模块中的无服务器云函数 `main` 函数。 |

## 返回值

该函数返回适用于无服务器云函数集成调用的例程派发器 `IntegrateDispatch` 实例。

## 异常

该函数可能会主动引发以下异常类型：

#### ValueError

参数值或类型不符合预期。

#### ModuleNotFoundError

该函数无法确定当前函数调用来自于哪一个 Python 模块。

## 示例

接下来我们将通过一段 Python 代码片段向您演示如何使用该函数：

```python
from tencent.cloud.serverless import functions

dispatcher = functions.use_routine_dispatcher()

@dispatcher.routine
def addend(
    value1: int,
    value2: int
) -> int:
    return value1 + value2
```

现在，Python 原生函数 `addend` 已向例程派发器注册并对外提供可名为 `addend` 的可调用例程。

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.5


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/use-routine-dispatcher-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
