Python-在守护程序中调用multiprocessing.pool [英] Python - calling multiprocessing.pool inside a daemon
问题描述
我有一个Python
脚本,它生成一个守护进程.在进程内部,我正在使用multiprocessing.pool
同时运行1
至4
进程.
I have a Python
script which spawns a daemon process. Inside the process, I am using multiprocessing.pool
to run 1
to 4
processes simultaneously.
当我在守护进程之外运行此代码时,它可以正常工作(即,当我设置run_from_debugger=True
-参见下面的代码),但是如果我通过守护进程(例如,run_from_debugger=False
)运行代码,则async_function
从不执行.
When I run this outside the daemon process, it works perfectly (i.e., when I set run_from_debugger=True
- see code below), but if I run the code via a daemon process, (i.e., run_from_debugger=False
), async_function
is never executed.
是否可以在daemon
进程内使用multiprocessing.pool
???
我正在使用Python-daemon 1.6
作为守护程序包(如果有的话).
Is it possible to use multiprocessing.pool
inside a daemon
process???
I am using Python-daemon 1.6
as my daemon package (if it matters).
代码:
def loop_callback(params):
#Spawn the process in the pool
# Because loop_callback is called many times, often faster than async_function executes,
# adding them to a pool allows for parallel execution.
pool.apply_async(async_function, params)
def run_service():
# loop is a method that can/will call loop_callback multiple times, and it will call
# loop_callback faster than the code in asyc_function executes
loop(alignment_watch_folder, sleep_duration)
#Class declaration
app = App()
#Declare a pool of processes
# processes=1 indicates serial execution
pool = Pool(processes=4)
#Either run from a daemon process or not
run_from_debugger = False
#Run the daemon process
if run_from_debugger:
run_service()
else:
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
任何建议将不胜感激.