未加星标

Python In Go - Introducing Grumpy

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

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 byDylan 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 CPython2.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.


Python In Go - Introducing Grumpy

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."

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: PythonGit
分页:12
转载请注明
本文标题:Python In Go - Introducing Grumpy
本站链接:http://www.codesec.net/view/524558.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(78)