Skip to content

Instantly share code, notes, and snippets.

@Hu-Wentao
Created November 12, 2024 14:23
Show Gist options
  • Select an option

  • Save Hu-Wentao/942c65789a7331eebc6828d4c7534eb8 to your computer and use it in GitHub Desktop.

Select an option

Save Hu-Wentao/942c65789a7331eebc6828d4c7534eb8 to your computer and use it in GitHub Desktop.
在py程序中, 使用函数而不是命令在新进程中启动huey
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