Python-异步调用函数()?
异步调用函数的最短方法是什么 用户应始终能够输入新值; 但是每个action()都必须排队Python-异步调用函数()?,python,asynchronous,Python,Asynchronous,异步调用函数的最短方法是什么 用户应始终能够输入新值; 但是每个action()都必须排队 def action(i): #takes a long time to be achieve while True: i = raw_input("Input your value: ") action(i) 使用多处理模块: from multiprocessing import Pool def action(i): #takes a long time to be
def action(i):
#takes a long time to be achieve
while True:
i = raw_input("Input your value: ")
action(i)
使用多处理模块:
from multiprocessing import Pool
def action(i):
#takes a long time to be achieve
worker_pool = Pool(processes=1)
while True:
i = raw_input("Input your value: ")
result = worker_pool.apply_async(action, [i], callback)
你也可以用芹菜做背景任务:
@celery_app.task(bind=True,max_retries=None)
def action(i):
#takes a long time to be achieve
while True:
i = raw_input("Input your value: ")
action.apply_async(args=[i])