Sanpreet
Sanpreet

Reputation: 103

Error in testing flask web app using Cloud SDK | Google Cloud on local system

I was in process of deploying my flask web app using google app engine and for achieving this step, I followed the below steps

  1. Creating the code for the application (Web Based)
  2. Creating a lib folder where all the packages are installed using the requirements.txt file
  3. Created appengine_config.py where the lib folder is added.
  4. Created the file app.yaml to test the application on the local system before deploying on the google app engine.

I was successful in these 4 steps. After the completion of these steps,

I run the below command

/usr/lib/google-cloud-sdk/bin/dev_appserver.py --admin_port=9000 --port=9999 app.yaml

As a result, I found the google app engine is running successfully on the local server. Please see the screenshot for this from here but when I tried to run the code at port 9999 on local server, I got the below error

  import multiprocessing
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "/usr/lib/python2.7/multiprocessing/util.py", line 41, in <module>
    from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

To resolve this error, I searched on the internet about this error and came up with the below conclusion

"You can't use multiprocessing on appengine. Multiprocessing is for creating and coordinating sub processes for parallelism. That is not an option on appengine. Appengine has other facilities like async methods, task queues and backends (which can use traditional threading)."

From my research on internet, above error is caused by multiprocessing and subprocess.py and google cloud engine does not support this.

My worry is if this is exactly the same as I understand then what is the way to tackle this as this would not let the code to be deployed on the google cloud engine.

Any ideas or solution is highly appreciated.

Upvotes: 0

Views: 132

Answers (1)

maniSidhu98
maniSidhu98

Reputation: 537

The conclusion that you have reached is absolutely correct in regards to App Engine Standard, which you seem to be using (based on the error that you are getting).

Due to how it’s implemented, App Engine Standard does not allow for multiprocessing. You can also check this Google Groups post for additional background.

Alternatively, you can use the Python runtime with App Engine Flex. That runtime uses Gunicorn, which uses workers to handle requests. With App Engine Flex, you will be able to configure the number of CPU cores for your application.

Keep in mind that App Engine Flex will incur costs based on usage rather than instance hours.

Upvotes: 1

Related Questions