在 celery 任务中运行 subprocess.popen 会给出状态代码 134(SIGABRT) 错误

问题描述

我正在尝试使用 subprocess.popen 在 celery 任务中运行一个子进程,但是一旦它执行命令,我就会得到 return code 134 的回报。下面是我运行命令的代码,我在其中创建了一个子进程并尝试获取生成的进程的标准输出,并且当/如果进程成功结束时,我希望获得 return code 为 0。

try:
    print("Executing command: {}".format(" ".join(args)))
    process = subprocess.Popen(
        args,stdout=subprocess.PIPE,universal_newlines=True
    )
    print("Processing Started...")
    while True:
        output = process.stdout.readline()
        print(output.strip())
        return_code = process.poll()
        if return_code is not None:
            print("RETURN CODE",return_code)
            # Process has finished,read rest of the output
            if return_code == 0:
                print("Processing Completed.")
            else:
                for output in process.stdout.readlines():
                    print(output.strip())
                print(
                    "Some Error occured during script execution. Script: {}".format(
                        " ".join(args)
                    )
                )
            break

except Exception as err:
    print("Error while excuting the script. Error: {}".format(err))
    return False
else:
    return return_code == 0

我在函数中传递的命令是作为字符串数组(称为 args)传递的,如下所示:

['/home/user/Metashape-pro/Metashape.sh','-r','/home/user/app/geoprocessing-api/init_doc.py','--project_name','mine_2','--geo_projection','epsg::4326','--execution_step','1']

因此,当我在控制台外部运行此命令时,它运行良好,但是当子进程在 celery 任务中运行它时,我立即从输出中获得 RETURN CODE 134,而打印语句中没有任何其他错误(所有输出都从芹菜日志文件中读取)。

我做错了什么,我没有为 subprocess.popen 传递环境,或者这里是否存在执行命令的用户权限问题?还是上面的代码中缺少 popen 的其他参数?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)