| ★ wanayoo — archive 1999 https://developers.google.com/appengine/docs/python/python27/using27 | Nouvelle recherche | Portail wanayoo |
This page provides installation and migration instructions for Python 2.7. You can use the information here to configure a new Python 2.7 application or update an existing application. The page has the following sections:
In order to use Python 2.7, an application must meet the following requirements:
Python 2.7 requires a special runtime configuration element in the header of app.yaml. Note that the threadsafe: [true | false] element is required for Python 2.7 applications. If true, App Engine sends requests concurrently; if false, App Engine sends them serially. The following app.yaml header enables concurrent requests:
application: myapp version: 1 runtime: python27 api_version: 1 threadsafe: true ...
The Python 2.7 runtime includes some third-party modules. Some of these are available by default; others are only available if configured. You can specify which version you want to use.
libraries: - name: PIL version: "1.1.7" - name: webob version: "1.1.1"
You can specify that the application should use the latest version of the module. This is useful if you're developing an application that doesn't have users yet: you don't need to track new versions. But if your application is being actively used, beware: you might be surprised that your application starts using a new not-backward-compatible library version. To use the latest version:
libraries: - name: PIL version: latest
For a list of supported libraries, please see Third-party Libraries.
The Python 2.7 runtime supports Web Server Gateway Interface (WSGI) applications natively. Instead of specifying a CGI handler (i.e. a Python script) in app.yaml and running your web application in your script, you can specify the application directly:
... handlers: - url: /.* script: myapp.app ...
You also need to move your WSGI application object to the global scope:
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, WebApp World!')
app = webapp2.WSGIApplication([('/', MainPage)])
You can still specify CGI script handlers in app.yaml.
Warning! If you plan to use concurrent requests, you must use WSGI handlers.
To use Python 2.7, you must specify a threadsafe element in app.yaml. If true, App Engine sends requests concurrently; if false, App Engine sends them serially.
application: myapp version: 1 runtime: python27 api_version: 1 threadsafe: true
The Python 2.7 runtime no longer restricts access to Python bytecode. Libraries that generate or manipulate bytecode (such as the jinja2 templating library) can do so in this runtime.
You can upload and use .pyc, but not in combination with .py files. You can upload .zip files containing .py or .pyc files (or a combination).
Threads can be created using the thread or threading modules. Note that threads will be joined by the runtime when the request ends, so the threads cannot run past the end of the request.
After configuring and updating the application, upload it using appcfg.py:
% appcfg.py update myapp
Once you've uploaded the application, you need to test it extensively to ensure backward compatibility. If you are experiencing issues, see the Considerations When Migrating Your Application section below, or check out the forums.
In Python 2.7, you must use specific versions of some App Engine features and third-party libraries. You will encounter backward-compatibility issues unless you test and update the application.
The following list identifies the primary compatibility issues and points to further resources to resolve them. Google recommends testing the application extensively after upgrading any of the following libraries:
app.yaml.Crypto.Util.randpool has been deprecated in favor of Crypto.Random. For more information, see What to do about RandomPool.