在gevent中主要使用Greenlet,给Python提供一个轻量级的协同程序,作为一个C的扩展模块.Greenlets主程序运行的所有系统进程是合理安排的. 这不同于任何multiprocessing或者multithreading提供的库和POSIX线程,这是真正的并行多处理器或多线程库提供真正的并行结构
首先感谢https://maskv.com/technology/192.html作者给我的帮助我参考老方法编译gevent1.0rc2成功但是无法运行gae最新版只能运行2.17原因就是缺少python2.7的支持现在博主给出啦方法搬过来方便大家
Tomato中python2.7+gevent1.0rc2环境的搭建
之前因为没有搜索到在Tomato中编译安装gevent的教程,就自己琢磨出来Tomato中python2.6+gevent0.13.8环境的搭建方法(点击这里查看),文章发布之后收到了众多的反馈。虽然Python官网当中的gevent最新版本为0.13.8,但Github上的gevent源码已经更新到了1.0rc2,最新版的gae本地客户端也集成的是gevent1.0rc2,在整合了一些反馈之后,在自己的路由器上成功更新了python和gevent。
首先卸载路由当中的python2.6及其相关组件,运行: 1
2
3
| ipkg -force-removal-of-dependent-packages remove python26
rm -rf /opt/local/lib/python2.6 #若挂载路径非/opt请自行修改
rm -rf /opt/lib/python2.6
|
之后更新、安装所需要的依赖包: 1
2
3
| ipkg update
ipkg upgrade
ipkg install busybox buildroot make grep openssl openssl-dev libuclibc++ wget-ssl python27 py27-setuptools
|
安装完成之后,我们要修复几个py27-setuptools当中的小错误。
首先easy_install的安装路径莫名其妙的指向了python2.5,不知是否只有我遇到了这个问题。修改 /opt/lib/python2.7/distutils/distutils.cfg 文件,将 1
| site-dirs = /opt/local/lib/python2.5/site-packages
|
修改为 1
| site-dirs = /opt/local/lib/python2.7/site-packages
|
其次easy_install的安装临时目录指向了/tmp目录,会造成安装某些组件时tmp剩余空间不足而导致的安装失败,我们要手动将其指定到挂载的U盘当中。
在/opt中创建tmp文件夹,修改 /opt/lib/python2.7/site-packages/setuptools/command/easy_install.py 文件,找到412行: 1
| tmpdir = tempfile.mkdtemp(prefix="easy_install-")
|
将其修改为: 1
| tmpdir = tempfile.mkdtemp(prefix="easy_install-",dir="/opt/tmp")
|
然后就可以使用easy_install安装greenlet与cython了(此步骤花费时间奇长无比): 1
2
3
4
| easy_install-2.7 greenlet
easy_install-2.7 cython
ln -s /opt/local/bin/cygdb /opt/bin/cygdb
ln -s /opt/local/bin/cython /opt/bin/cython
|
之后下载gevent:
直接编译会报错,因为使用了mips2的sync指令,在gae的issues上找到了答案。心得编译前记得开启虚拟内存
修改 /libev/ev.c 文件,找到604行的:参考https://code.google.com/p/gae/issues/detail?id=7823 1
| #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
|
修改为: 1
| #define ECB_MEMORY_FENCE __asm__ __volatile__ (".set mips2; sync; .set mips0": : :"memory") |
执行 1
| python2.7 setup.py install
|
下载并安装pyOpenSSL
安装结束之后,运行gae可能会提示.python-eggs错误,我们可以手动指定缓存目录。
修改gae的proxy.py文件,在:
下一行添加: 1
| os.environ['PYTHON_EGG_CACHE'] = '/opt/.python-eggs'
|
或者可以将 gevent-1.0rc2-py2.7-linux-mips.egg 解包: 1
2
3
4
5
| cd /opt/local/lib/python2.7/site-packages
mv gevent-1.0rc2-py2.7-linux-mips.egg gevent-1.0rc2-py2.7-linux-mips.egg.zip
mkdir gevent-1.0rc2-py2.7-linux-mips.egg
cd gevent-1.0rc2-py2.7-linux-mips.egg
unzip /opt/local/lib/python2.7/site-packages/gevent-1.0rc2-py2.7-linux-mips.egg.zip
|
再次运行gae,应该不会再有错误提示了。
easy_install-2.7 cython过程漫长rg200e历时大概8个多小时完成安装大家耐心等待教程是没有问题的
Using /opt/local/lib/python2.7/site-packages/greenlet-0.4.0-py2.7-linux-mips.egg
Processing dependencies for greenlet
Finished processing dependencies for greenlet
root@Tomato-arctic:/tmp/home/root# easy_install-2.7 cython
Searching for cython
Reading http://pypi.python.org/simple/cython/
Reading http://www.cython.org
Reading http://cython.org
Best match: Cython 0.17.3
Downloading http://cython.org/release/Cython-0.17.3.zip
Processing Cython-0.17.3.zip
Running Cython-0.17.3/setup.py -q bdist_egg --dist-dir /opt/tmp/easy_install-hCF
2Og/Cython-0.17.3/egg-dist-tmp-Y0XMdp
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Plex.Actions ...
Compiling module Cython.Compiler.Lexicon ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.FlowControl ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Runtime.refnanny ...
warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.h' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.pxd' under directory 'Cython/Utility'
/opt/tmp/easy_install-hCF2Og/Cython-0.17.3/Cython/Plex/Scanners.c:7091: warning:
'__Pyx_CyFunction_New' defined but not used
Adding Cython 0.17.3 to easy-install.pth file
Installing cygdb script to /opt/local/bin
Installing cython script to /opt/local/bin
Installed /opt/local/lib/python2.7/site-packages/Cython-0.17.3-py2.7-linux-mips.
egg
Processing dependencies for cython
Finished processing dependencies for cython
root@Tomato-arctic:/tmp/home/root# ln -s /opt/local/bin/cygdb /opt/bin/cygdb
ln: /opt/bin/cygdb: File exists
root@Tomato-arctic:/tmp/home/root# ln -s /opt/local/bin/cython /opt/bin/cython
ln: /opt/bin/cython: File exists
root@Tomato-arctic:/tmp/home/root#
|