python
共 23 篇文章
python 字典的扩展变形
class AttrDict(dict): """ http://stackoverflow.com/questions/4984647/\ accessing-dict-keys-like-an-attribute-in-python http://bugs.python.org/issue1469629 """ def __init__(self, source): super(AttrDict, self).__init__(source) def __getattr__(self, key): return self[key] def __setattr__(self, key, v…
geohash的应用 附近地址搜索
http://en.wikipedia.org/wiki/Geohash 简单使用 geohash, redis,bottle, python-geohash 来实现 restful api的地理位置附近人搜素 from bottle import Bottle, run import time import json from redis_pool import Redis R = Redis().connection_pool() import geohash app = Bottle() @app.route('/v1/mark/<longitude:float>/<latitude:…
2013-08-16 11:17 · python
openstack swift GB/month
http://www.buildcloudstorage.com/2012/01/can-openstack-swift-hit-amazon-s3-like.html
swift benchmark 转载
具体测试移步到下面的blog URL http://www.zmanda.com/blogs/?tag=swift-benchmark
openstack-folsom-architecture 记录
http://ken.pepple.info/openstack/2012/09/25/openstack-folsom-architecture/
An Introduction to the Python Web Server Gateway Interface
非原创,来源互联网 In Brief WSGI is a specification, laid out in PEP 333, for a standardized interface between Web servers and Python Web frameworks/applications. The goal is to provide a relatively simple yet comprehensive interface capable of supporting all (or most) interactions between a Web server and …
openstack swift Cluster Health and Telemetry
之前看swift的code主要关注在ring,proxy-server, object-server, container-server, account-server这些组件上,一次有人问我swift如何monitoring的,哦,fuck 我漏了这里,不过我想swift使用WSGI应该比较容易在filter加一个 侦测状态的filter_factory 到原有的WSGI的Pipeline,马上去翻code,果然,这货解耦做的很强悍嘛, https://github.com/openstack/swift/blob/master/swift/common/middleware/recon.…
paste deploy python ini 配置文件简单说明
配合 http://www.python.org/dev/peps/pep-0333/ http://pythonpaste.org/deploy/ 看下面的example(从网络上改造而来,出处URL也搞忘记的),很快会对python的paste如何组织wsgi有一个简单的了解, pastedeploylab.ini [default] key1=value1 key2=value2 key3=values [composite:pdl] use=egg:Paste#urlmap /:root /calc:calc [filter:logrequest] username = root p…
2012-12-03 13:27 · python
python 反射
如何在python中实现 类似java中, Class.forName().newInstance() 的功能 静态导入 tommy@ubuntu:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [gcc 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from time import time >>> globals() {'__builtins__': <module '__builtin_…
2012-03-20 10:31 · python
如何友好的 监控与管理 Linux 进程
在做视频编解码的程序,需要fork子进程去调用转码的tools做encode, 这里面就需要能很好的控制进程,让进程类似于跑在沙漏里面,安全,可控的运行, 实现进程的管理接口,其实比较简单的,所有的进程信息来源,均来自 /proc 文件系统 因为是所有进程相关的信息都是通过读取内存proc文件系统,所以没有任何性能问题, tommy@tommy-desktop:~$ cd /proc/ tommy@tommy-desktop:/proc$ ls 1 1176 13 1340 14 1451 15736 20444 20460 240 33 43 59 636 756 8 9299 crypt…
2010-11-11 12:57 · python
Webpy + Nginx with FastCGI
Requirements * Nginx 0.8.* or 0.7.* (with fastcgi and rewrite module). * Webpy 0.32 * Spawn-fcgi 1.6.2 * Flup Older versions may work, but aren't tested. Resources * Nginx wiki * Spawn-fcgi * Flup Notes * You may replace index.py with your own file name. * /path/to/www Is the path to the directory …
2010-11-10 16:50 · python
worker pool
http://celeryq.org/ Overview This is a high level overview of the architecture. he broker delivers tasks to the worker servers. A worker server is a networked machine running celeryd. This can be one or more machines depending on the workload. The result of the task can be stored for later retrieva…
2010-09-27 17:28 · python
sandbox for python
遇到一台机器上部署多个不同的python程序,管理其之间import不同的libs而麻烦 http://virtualenv.openplans.org/ virtualenv通过隔离包目录和系统环境参数来实现多个相对独立的虚拟环境。 这样可避免过多的第三方库因版本依赖造成问题。 同时每个独立的虚拟环境只需通过打包即可分发,方便了系统部署。 安装 [root@ct53-64-base ~]# pip install -U virtualenv Downloading/unpacking virtualenv Downloading virtualenv-1.5.1.tar.gz (1.4Mb…
2010-09-27 14:47 · python
python get host ip socket
[root@ct53-64-base tools]# python Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [gcc 4.1.2 20080704 (red hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >>> s.connect(("10.224.178.16…
2010-08-11 08:57 · python
整数转换成二进制
>>> bin = lambda n : (n > 0) and (bin(n/2) + str(n%2)) or '' >>> bin(1) '1' >>> bin(20) '10100' >>>
2010-05-20 09:25 · python
python获得磁盘剩余空间 statvfs
在linux上工作大家都会用到df命令 [tommy@tommy-1 ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 4.8G 389M 4.2G 9% / /dev/sda7 271G 3.5G 254G 2% /home /dev/sda3 4.8G 1.1G 3.5G 24% /usr /dev/sda2 4.8G 199M 4.3G 5% /var /dev/sda1 99M 18M 77M 19% /boot tmpfs 997M 0 997M 0% /dev/shm 这个df命令有个问题,即是磁盘的某个…
2010-04-01 14:43 · python
python 监控 linux memory 使用率
定时获得服务器上内存的使用率 linux的内存使用跟win是不一样的,以下linux命令获得内存使用率是,linux os 预先分配的,实际上可能还没有使用这么多内存,可以使用 $free -m total used free shared buffers cached Mem: 1942 1671 271 0 404 731 -/+ buffers/cache: 535 1406 Swap: 6015 5 6010 实际使用的内存是 535M 但是linux os占据了 1671M 对比下,可以使用以下代码获得操作系统占用的内存 re_meminfo_parser = re.compile…
2009-11-09 13:30 · python
python 监控 linux cpu 使用率
最近一个应用特别的吃cpu,又是和已有的应用复用机器,故所以对机器的cpu监控显的重要起来 当cpu高到某一限度,及时报警 def _read_cpu_usage(self): """Read the current system cpu usage from /proc/stat.""" try: fd = open("/proc/stat", 'r') lines = fd.readlines() finally: if fd: fd.close() for line in lines: l = line.split() if len(l) < 5: continue if l[0].s…
2009-11-09 13:18 · python
python异常捕获try except
python的异常处理机制设计的比较传统,在日常的开发中,基本满足我的需要 下面就python的异常,几点小小的讨论 try...except tommy@lab3:~$ python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [gcc 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1/0 Traceback (most recent call last): File "<stdin>", line 1…
2009-06-29 13:14 · python
python adodb 支持mysql非标准端口
python对数据库的操作大多是基于 MySQLdb 模块 http://mysql-python.sourceforge.net/ 但是,一般情况下大家都很少直接去调用 MySQLdb 去操作数据库 大多会借助 adodb http://phplens.com/lens/adodb/adodb-py-docs.htm 小用了一下 adodb发现,还是比较强大的,(简单,直观) import adodb; conn = adodb.NewADOConnection('mysql') conn.Connect('server','user','pwd','db') cursor = conn.…
2009-06-14 19:08 · python