文档章节

在 PyPy2.x 上 安装 Gevent (源码安装)

heshuping92
 heshuping92
发布于 2014/01/10 15:57
字数 639
阅读 169
收藏 0



 python / gevent / pypy


PyPy has been on my radar for a while but I have never really brought myself to the point of actually trying it.  Recently, a notification caught to my attention stating PyPy 2.0.2 was released and had support to run Gevent.  Good news! I was looking at speed improvements for my Wishbone library and decided to spend some effort into getting PyPy with Gevent up and running.  The information available explaining how to setup Gevent in PyPy is rather sparse which might be a bit time consuming when you have to figure out the bits and pieces.  After some tinkering I got PyPy with Gevent up and running within virtualenv on a Fedora host.  Here are my notes, It might be useful for you to and save some previous time:

Before you proceed make sure you have read the "building-from-source" instructions from the PyPy site.

Compiling

PyPy has some binaries available but they can only be used on Ubuntu so we'll have to download the source and compile from scratch.

Start by downloading the source and unpack the tarball.

$ tar -xvjf pypy-2.0.2-src.tar.bz2

Before starting to compile make sure we have all required libraries installed:

$ yum install openssl-devel libffi-devel ncurses-devel expat-devel bzip2-devel

Move into our unpacked directory and start the compilation.  In the below examples we use the Python version which comes with your os to run the compilation process.

$ cd pypy-2.0.2-src/pypy/goal
$ python ../../rpython/bin/rpython --opt=jit targetpypystandalone.py
这里我需要至少3g内存去编译pypy环境

The compilation process is fairly lengthy.  It took +- 90 minutes(!) on my laptop for the process to finish.

Prepare the installation

When the compilation has finished we should have a file called pypy-c in the current directory.

Best is to move the complete install to the /opt/ directory and rename the directory appropriately.

$ mv pypy-2.0.2-src /opt/pypy-2.0.2

Now let's use virtualenv to create an isolated instance of PyPy, keeping your freshly compiled one clean:

$ virtualenv -p /opt/pypy-2.0.2/pypy/goal/pypy-c ~/pypy-2.0.2
$ . ~/pypy-2.0.2/bin/activate

Gevent

First make sure you have following library installed:

$ yum install libev-devel

Install the cffi module:

(pypy-2.0.2)$ pip install cffi

Install a version of Gevent which has been modified to run on PyPy.  Make sure we install Gevent inside our virtualenv:

$ git clone https://github.com/schmir/gevent.git
$ cd gevent
$ git checkout pypy-hacks
$ . ~/pypy-2.0.2/bin/activate(pypy-2.0.2)
$ pypy setup.py install

Now we need one last modification which implements gevent.core as cffi module:

$ git clone https://github.com/gevent-on-pypy/pypycore.git
$ cd pypycore
$ . ~/pypy-2.0.2/bin/activate(pypy-2.0.2)
$ CFLAGS=-O2 pip install -e
 .

If setup.py complains it can not locate ev.h it's possible the library search path isn't complete.  In that case locate the location of the file and add that directory to pypycore.py (starts at line 207) using the include_dirs variable:

libev = C = ffi.verify(""" // passed to the real C compiler#includevoid gevent_noop(struct ev_loop *_loop, void *watcher, int revents) { }""", libraries=["ev"], include_dirs=["/usr/include/libev"])

Test

Before starting PyPy we have to make sure gevent used the right gevent.core:* *

$ export GEVENT_LOOP=pypycore.loop

Now start PyPy and execute some gevent code:

$ . ~/pypy-2.0.2/bin/activate(pypy-2.0.2)
$ pypy
Python 2.7.3 (5acfe049a5b0cd0de158f62553a98f5ef364fd29, Jun 01 2013, 08:37:22)[PyPy 2.0.2 with GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux2Type "help", "copyright", "credits" or "license" for more information.And now for something completely different: ``PyPy 1.3 released (windowsbinaries included)''
>>>> import gevent
>>>> for _ in xrange(100):.... gevent.spawn(gevent.sleep, 1)

Conclusion

As you can see setting up PyPy with Gevent requires a bit of work. Once setup into a virtualenv it's really easy to use, experiment and rebuild.

Have a lot of fun running Gevent on PyPy!


© 著作权归作者所有

heshuping92
粉丝 2
博文 2
码字总数 2796
作品 0
深圳
私信 提问
Win7 + VS2010 + Python2.7.5 安装 gevent

昨天折腾了下gevent,做个简单的记录。具体环境本文标题已经说得很明白了, win7是32位的 1. 下载gevent安装包 去gevent官网下载个source包, 地址是这里 http://pypi.python.org/packages/so...

cardinalinux
2013/09/10
0
0
Ubuntu 安装gevent

Gevent是一个基于greenlet的Python的并发框架,以赖于greenlet和libevent库,因此安装Gevent前,首先需要安装greenlet和libevent。 libevent的安装,这里就不介绍了,网上的安装教程一大箩,...

jackliu8722
2012/07/16
0
0
Locust install on windows Locust 在win上安装 笔记

首先,安装python,2.7, Locust 需要的版本 (Locust requires Python 2.6+. It is not currently compatible with Python 3.x.) 然后把python配置到环境变量,再安装,pip。 python,pip...

menglinxi_a
2015/08/05
0
0
协程-gevent

协程用gevent实现, 依赖libevent和greenlet ###安装 1. 安装libevent yum install libevent 2. 安装easyinstall 【1】wget -q http://peak.telecommunity.com/dist/ezsetup.py 【2】python ......

cloves
2017/05/12
0
0
Cent os 下 libevent,greenlet,gevent 的安装 和介绍 记录

libevent libevent是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部使用 select、epoll、kqueue等系统调用管理事件机制。著名分布式缓存软件memcached也是libevent base...

G0561
2014/04/05
0
0

没有更多内容

加载失败,请刷新页面

加载更多

两数的最大公约数

hello,复习一下数学知识! 最大公因数,也称最大公约数、最大公因子,指两个或多个整数共有约数中最大的一个。 因为之前做一个小功能,需要先计算一下数组的最大公约数,所以我就想记录一下...

woshixin
今天
3
0
学习Node.js的电子书大全

在这里,与大家分享一批很有用的 Node.js 的电子书资源。Node 是一个服务器端的 JavaScript 解释器,它将改变服务器应该如何工作的概念。它的目标是帮助程序员构建高度可伸缩的应用程序,编写...

jay603
今天
61
0
《伟大的博弈》读后感作文4100字

《伟大的博弈》读后感作文4100字: 五一小长假,作为工厂员工,没能跟上大家放假的步伐,窝家里两天没出门,逼着自己看完《伟大的博弈》,感触颇多。似乎不能消化,先记录第一遍作为幼稚的见...

原创小博客
昨天
5
0
单点登录-基于Redis+MySQL实现单点登录(SSO)

1. 为什么要用单独登录? 主要便于公司内部多系统统一认证授权管理,一次登录可访问多个跨域系统,也同时更加方便统一管理用户登录(员工离职需要拿掉登录权限、统计所有用户对系统的登录请求...

秋日芒草
昨天
2
0
827. Making A Large Island

思想: 将所有连通的 1 分成一个组,分配编号,然后使用BFS统计1的个数,得到这个组的面积。 遍历格子里所有为 0 的元素,检查四个方向的1所在的组并加上这个组面积。于是得到当前元素为 0 ...

reter
昨天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部