|Python In Go - Introducing Grumpy|
|Written by Kay Ewbank|
|Thursday, 12 January 2017|
Google has developed an experimental Python runtime for Go that translates Python code to Go, then runs the code in the Go runtime.
The thinking behind this crazy sounding scheme is to find a way to make concurrent workloads perform well. As a post on the Google open source blog by Dylan Trotter of YouTube Engineering explains:
"Google runs millions of lines of Python code. The front-end server that drives youtube.com and YouTube’s APIs is primarily written in Python, and it serves millions of requests per second! YouTube’s front-end runs on CPython 2.7, so we’ve put a ton of work into improving the runtime and adapting our application to work optimally within it."
Trotter explains that while the work has been relatively successful, the problem remains that it's very difficult to make concurrent workloads perform well on CPython. Other Python runtimes all involved trade-offs, so:
"we asked ourselves a crazy question: What if we were to implement an alternative runtime optimized for real-time serving?"
The choice of Go as the platform came down to a number of benefits, including lightweight threads and first class language interoperability.
The result was Grumpy, an experimental Python runtime for Go that translates Python code into Go programs, and those transpiled programs run seamlessly within the Go runtime.
The goal is for Grumpy to be a drop-in replacement runtime for any pure Python project. There are two limitations because of the design choices made by the developers. Firstly, because there's no support for C extension modules, Grumpy can't make use of existing Python C extensions. This choice was made because it gave the developers flexibility to design an API and object representation that scales for parallel workloads.
The second limitation is that Grumpy is not an interpreter; Grumpy programs are compiled and linked just like any other Go program. This limits development and deployment flexibility, but creates opportunities to optimize performance at compile time via static program analysis. It also means that interoperability with Go code becomes both powerful and straightforward.: Grumpy programs can import Go packages just like Python modules.
A limitation that could be of more consequence to Python developers is that Grumpy runs Python 2.7 rather than Python 3. The developers at Google say this is because they have a large codebase in Python 2.7 to support. In a conversation on Github, Dylan Trotter said:
"I definitely would like to support Python 3. It's just a bunch of work. Probably requires forking grumpy and building out all the v3 features."
"Another path may be to support Python 3 features in the existing Grumpy runtime and transpiler at the risk of making things less maintainable."
Grumpy is still alpha software, but most of the language constructs and many core built-in types work like you’d expect. Trotter says that:
"there are still holes to fill — many built-in types are missing methods and attributes, built-in functions are absent and the standard library is virtually empty. If you find things that you wish were working, file an issue so we know what to prioritize. Or better yet, submit a pull request."
or email your comment to: firstname.lastname@example.org
|Last Updated ( Thursday, 12 January 2017 )|