Created
November 12, 2024 14:23
-
-
Save Hu-Wentao/942c65789a7331eebc6828d4c7534eb8 to your computer and use it in GitHub Desktop.
在py程序中, 使用函数而不是命令在新进程中启动huey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import logging | |
| import sys | |
| from huey.bin.huey_consumer import load_huey | |
| from huey.consumer_options import ConsumerConfig | |
| def run_huey(instance_path: str, config: str): | |
| huey_instance = load_huey(instance_path) | |
| config = ConsumerConfig(**json.JSONDecoder().decode(config)) | |
| if sys.platform == 'win32' and config.worker_type == 'process': | |
| print('Error: huey cannot be run in "process"-mode on Windows.') | |
| sys.exit(1) | |
| config.setup_logger(logging.getLogger('huey')) | |
| consumer = huey_instance.create_consumer(**config.values) | |
| consumer.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment