python子进程在Google云功能中不起作用

问题描述 投票:1回答:1

我需要通过Google Cloud功能中的python中的Subprocess获得一些执行的过程。

import subprocess
import os
def hello_world(request):
    print(subprocess.call(["echo", "hello","world"]))

预期输出:你好,世界

实际输出:0

Google函数会阻止子流程的执行还是我需要以其他方式接收输出

python subprocess google-cloud-functions
1个回答
0
投票

请记住,Cloud Functions是无服务器的计算平台,主要功能之一是没有要配置,管理,修补或更新的服务器。

应该使用python中的子进程来访问系统命令,因此,基本上,您试图从运行Cloud Function的计算机获得响应,而这是不可能的。

在您的特定情况下,使用以下代码将获得预期的输出:

def hello_world(request):

    return f'Hello, world!'
© www.soinside.com 2019 - 2024. All rights reserved.