2015-10-05 90 views
1

我有Python Celery作为守护进程运行,Celerybeat在亚马逊Linux框上拾取任务。当我运行我的测试任务时,它没有发生任何事情就完成了。在运行Python Celery作为守护进程时无法执行Ruby脚本

@app.task 
def test(): 
    print("Testing 123") 
    return 0 

然而,当我尝试使用Python的subprocess模块,它轮询的时间屈指可数,以火了一个Ruby脚本,然后用1返回代码退出。

@app.task 
def run_cli(): 
    try: 
     process = subprocess.Popen([filepath, "run"], stdout=subprocess.PIPE) 

     while not process.poll(): 
      data = process.stdout.readline() 
      if data: 
       sys.stdout.write("Polling: " + data.decode("utf-8")) 
      else: 
       sys.stdout.write("Polling: No Data.") 

     return process.wait() 
    except Exception as e: 
     print(e) 

我已经证实,当使用tasks.run_cli.apply()在Python壳芹菜工人执行Ruby脚本顺利运行。那么,芹菜守护进程为什么不执行这个任务?

预警:我对Python非常陌生&芹菜和我的Linux技能很差,所以我很抱歉,如果它是明显的。任何帮助深表感谢。

回答

0

对于轮询结束Ruby脚本必须发送一个非零信号返回到Python脚本,否则该过程完成,Python继续轮询而不接收数据。由于对process.stdout.readline()的错误响应表明(我怀疑)脚本的处理已完成,所以也可以在else条件中跳出循环。

相关问题