Skip to main content
Python Celery

简介

不多说,直接开干

下载

pipy 获取下载链接。

pip install celery==5.4.0

MarshioLess than 1 minutepythoncelery
Python UV

简介

An extremely fast Python package and project manager, written in Rust.

下载

official installation guide

# 有 curl
curl -LsSf https://astral.sh/uv/install.sh | sh

# 有 wget
wget -qO- https://astral.sh/uv/install.sh | sh

MarshioAbout 1 minpythoncelery
Python 装饰模式
import time


def retry(retry_times: int = 3):
    def decorator(func):
        def wrapper(*args, **kwargs):
            for i in range(retry_times):
                try:
                    return func(*args, **kwargs)
                except Exception as e:
                    print(f"{str(func).split(' ')[1]} retry {i + 1} times cause exception {e}")
                    if i == retry_times - 1:
                        raise e

        return wrapper

    return decorator


def timer():
    def decorator(func):
        def wrapper(*args, **kwargs):
            start = time.perf_counter()
            try:
                return func(*args, **kwargs)
            except Exception as e:
                raise e
            finally:
                end = time.perf_counter()
                print(f"{func.__name__} cost {end - start} seconds")

        return wrapper

    return decorator


MarshioLess than 1 minutepython