Anonymous avatar Anonymous committed 8fba5bd

fixed support for subprocess module

Comments (0)

Files changed (2)

         global env_ext
         env_ext['HOME'] = PROJECT_DIR
 
+    # Get the subprocess module into the dev_appserver sandbox.
+    # This module is just too important for development.
+    # The second part of this hack is in runserver.py which adds
+    # important environment variables like PATH etc.
     if not on_production_server:
-        from google.appengine import dist
-        if 'subprocess' in dist.__all__:
-            dist.__all__.remove('subprocess')
-        from google.appengine.tools.dev_appserver import os as clean_os
-        os.fdopen = clean_os.fdopen
+        try:
+            from google.appengine.api.mail_stub import subprocess
+            sys.modules['subprocess'] = subprocess
+        except ImportError:
+            import logging
+            logging.warn('Could not add the subprocess module to the sandbox.')
 
     os.environ.update(env_ext)
 

management/commands/runserver.py

     # Reset logging level to INFO as dev_appserver will spew tons of debug logs
     logging.getLogger().setLevel(logging.INFO)
 
+    # Allow to run subprocesses
+    from google.appengine.tools import dev_appserver
+    try:
+        env = dev_appserver.DEFAULT_ENV
+        dev_appserver.DEFAULT_ENV = os.environ.copy()
+        dev_appserver.DEFAULT_ENV.update(env)
+    except AttributeError:
+        logging.warn('Could not patch the default environment. '
+                     'The subprocess module will not work correctly.')
+
     # Append the current working directory to the arguments.
     dev_appserver_main.main([progname] + args + [os.getcwdu()])
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.