Skip to content

'subprocess' module monkey-patch warning in boot.py #53

@changemewtf

Description

@changemewtf

WARNING boot.py Could not add the subprocess module to the sandbox: 'module' object has no attribute 'Popen'

This happens at the end of the setup_project() method in boot.py, in the try/except clause labeled via comment as "Restore the real subprocess module."

        elif not on_production_server:
        try:
            # Restore the real subprocess module.
            from google.appengine.api.mail_stub import subprocess
            sys.modules['subprocess'] = subprocess
            # Re-inject the buffer() builtin into the subprocess module.
            from google.appengine.tools import dev_appserver
            subprocess.buffer = dev_appserver.buffer
        except Exception, e:
            logging.warn("Could not add the subprocess module to the "
                         "sandbox: %s" % e)

I'm not sure why this code chooses to import subprocess from the google.appengine.api.mail_stub module, because the "real" import of subprocess at the top of mail_stub.py appears to be overriden at some point with the monkey-patched subprocess module, which of course does not have a Popen attribute.

The caught error is thrown during the import of mail_stub.py itself:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 196, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 266, in _LoadHandler
    __import__(cumulative_path)
  File "/Users/mcantor/src/_____/src/_____/djangoappengine/main/__init__.py", line 28, in <module>
    setup_env()
  File "/Users/mcantor/src/_____/src/_____/djangoappengine/boot.py", line 75, in setup_env
    setup_project()
  File "/Users/mcantor/src/_____/src/_____/djangoappengine/boot.py", line 175, in setup_project
    from google.appengine.api.mail_stub import subprocess
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py", line 48, in <module>
    class MailServiceStub(apiproxy_stub.APIProxyStub):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py", line 214, in MailServiceStub
    popen=subprocess.Popen,
AttributeError: 'module' object has no attribute 'Popen'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions