Skip to main content

A suite kit for personal academic life.

Project description

twist-academic

在实验或脚本结束时,通过飞书群机器人 webhook 发一条通知。无第三方运行时依赖。

安装

pip install twist-academic

配置

在项目根目录创建 .env(安装后 import twist_academic 会自动加载当前工作目录下的 .env):

TWIST_LARK_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/your-token
# 若机器人在飞书后台开启了签名校验:
# TWIST_LARK_SECRET=your_sign_secret

用法

from twist_academic import notify

@notify
def train():
    ...

@notify(title="bert 微调")
def run_experiment():
    ...

# 直接发一条纯文本
notify("脚本已跑完,记得看结果。")

@notify 会在函数正常结束或抛异常后各发一条消息(含耗时、主机名;失败时带 traceback)。

集群 / 并行时避免刷屏

在 SLURM array、本地多进程等场景下,每个子任务若都 @notify,会产生大量重复消息。库会在以下情况自动不发送notify / maybe_notify / @notify 均生效):

条件 说明
SLURM_ARRAY_TASK_ID 已设置 SLURM array 的每个 task 默认静音;可用 SBATCH --mail-type=END,FAIL 收邮件
NO_NOTIFY=1(或 true / yes / on 任意环境显式关闭通知,便于子进程或调试
# 子进程 / 单次调试不发飞书
export NO_NOTIFY=1
python worker.py
from twist_academic import maybe_notify, notifications_suppressed

if not notifications_suppressed():
    notify("仅主进程汇总后发一条")

maybe_notify("与 notify(msg) 相同,受同一套静音规则约束")

测试

uv sync --dev
make test

# 向真实 webhook 发一条(需配置 TWIST_LARK_WEBHOOK)
pytest tests/test_notification.py -m integration

pyproject.toml 中已注册 integration marker。

开发

pre-commit run --all-files
uv build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twist_academic-0.3.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twist_academic-0.3.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file twist_academic-0.3.0.tar.gz.

File metadata

  • Download URL: twist_academic-0.3.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for twist_academic-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2300ee424489e6f9ae4829ef8264cec50704916d7e2f7f80bb84fe51c6d6ae6d
MD5 2998f966be243152f76d29d131a5a503
BLAKE2b-256 53b47ac62a300845ab8e55ac94c718b23b4c92d020ba009d2234f5027c6af5d0

See more details on using hashes here.

File details

Details for the file twist_academic-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: twist_academic-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for twist_academic-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e768b0a3729c5707e28893ca5e6acb77b3ce547265ffe892a060c2bbb82021d
MD5 e4e87fa9601e3b4bfd087204f87ee92e
BLAKE2b-256 04e0352fc44496acca299dfc997f30bb8d98a27f834d9e4e38ff29e8d4b832f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page