Cannot import subprocess.call when running google

2019-06-12 03:13发布

I am beginning to test google app engine for running my flask app. I can run the app directly using flask run without a problem. My app.yaml looks like this

runtime: python27
api_version: 1
threadsafe: true

# [START handlers]
handlers:
- url: /static
  static_dir: CameraMeerat/static
- url: /.*
  script: CameraMeerkat.app
# [END handlers]

When running dev_appserver.py I get

  File "C:\Users\Ben\Documents\CameraMeerkat\Frontend\CameraMeerkat\commands.py", line 5, in <module>
from subprocess import call
ImportError: cannot import name call
INFO     2017-07-21 21:26:37,585 module.py:813] default: "GET / HTTP/1.1" 500 -

From my python shell I can run that command

from subprocess import call
help(call)
Help on function call in module subprocess:

call(*popenargs, **kwargs)
    Run command with arguments.  Wait for command to complete, then
    return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])

What might be going on here? Subprocess is not a module that can be installed, or really messed with. Similar to unanswered here

ImportError: cannot import name Popen google cloud compute delpoyment error ?

1条回答
贪生不怕死
2楼-- · 2019-06-12 03:58

This is one of the limitation imposed by the GAE standard environment Python sandbox. From The sandbox (emphasis mine):

An App Engine application cannot:

  • write to the filesystem. Applications must use Cloud Datastore for storing persistent data. Reading from the filesystem is allowed, and all application files uploaded with the application are available.

  • respond slowly. A web request to an application must be handled within a few seconds. Processes that take a very long time to respond are terminated to avoid overloading the web server.

  • make other kinds of system calls.

One of the disallowed system calls is subprocess.call. The development server will raise an exception as it contains a modified version of subprocess.

If your app requires such call you may need to switch to the flexible enviroment. See also Choosing your App Engine environment

查看更多
登录 后发表回答