如何在Google Cloud函数中作为子进程运行python脚本

2024-10-02 14:16:08 发布

您现在位置:Python中文网/ 问答频道 /正文

import subprocess 
import os

def execute(): 
    code = "def Solution():\n\tprint('Hello')\n\nSolution()\n"
    f = open('/tmp/Solution.py','w')
    f.write(code+'\n')
    f.close() 
    s = subprocess.check_output("python /tmp/Solution.py", shell = True) 
    return s

我正在从云函数处理程序调用execute函数。这在本地有效,但在gcloud子进程上有效。check_输出返回非零退出代码

是因为gcloud运行时环境找不到python解释器吗?在这两种情况下,我怎么能做这样的事情?我错过了什么?我的日志中没有太多信息,所以我被卡住了

谢谢


Tags: 函数pyimporthelloexecuteosdefcheck

热门问题