haiyun.me - Python









Search Preview

Python - 海运的博客

haiyun.me
海运的博客 首页 关于 分析网站 文章归档 参考手册 在线工具 常用命令
.me > haiyun.me

SEO audit: Content analysis

Language Error! No language localisation is found.
Title Python - 海运的博客
Text / HTML ratio 66 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud = print import message_queues data sgetpeername fd_to_socket connection Comments Python events client_address timeout elif install 分类:Python outputs sclose del socket
Keywords consistency
Keyword Content Title Description Headings
= 71
print 35
import 18
message_queues 16
data 11
sgetpeername 9
Headings
H1 H2 H3 H4 H5 H6
1 5 0 0 3 0
Images We found 1 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
= 71 3.55 %
print 35 1.75 %
import 18 0.90 %
message_queues 16 0.80 %
data 11 0.55 %
sgetpeername 9 0.45 %
fd_to_socket 8 0.40 %
connection 7 0.35 %
Comments 6 0.30 %
Python 6 0.30 %
events 6 0.30 %
client_address 5 0.25 %
timeout 5 0.25 %
elif 5 0.25 %
install 5 0.25 %
分类:Python 5 0.25 %
outputs 5 0.25 %
sclose 5 0.25 %
del 5 0.25 %
socket 5 0.25 %

SEO Keywords (Two Word)

Keyword Occurrence Density
message_queues = 6 0.30 %
分类:Python No 5 0.25 %
if s 5 0.25 %
s in 5 0.25 %
No Comments 5 0.25 %
coding utf8 4 0.20 %
usrbinpython coding 4 0.20 %
else print 4 0.20 %
data 客户端: 4 0.20 %
timeout = 4 0.20 %
= message_queues 4 0.20 %
fd_to_socket = 4 0.20 %
utf8 import 4 0.20 %
2015 分类:Python 4 0.20 %
del message_queues 4 0.20 %
sclose del 4 0.20 %
print 收到数据: 3 0.15 %
in outputs 3 0.15 %
t = 3 0.15 %
message_queues putdata 3 0.15 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
分类:Python No Comments 5 0.25 % No
usrbinpython coding utf8 4 0.20 % No
sclose del message_queues 4 0.20 % No
2015 分类:Python No 4 0.20 % No
coding utf8 import 4 0.20 % No
print 收到数据: data 3 0.15 % No
msg = message_queues 3 0.15 % No
= message_queues get_nowait 3 0.15 % No
message_queues get_nowait except 3 0.15 % No
get_nowait except QueueEmpty 3 0.15 % No
except QueueEmpty print 3 0.15 % No
for s in 3 0.15 % No
else print 发送数据: 3 0.15 % No
True print 等待活动连接 3 0.15 % No
try msg = 3 0.15 % No
while True print 3 0.15 % No
data print 收到数据: 3 0.15 % No
if data print 3 0.15 % No
message_queues = QueueQueue 3 0.15 % No
not events print 2 0.10 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
usrbinpython coding utf8 import 4 0.20 % No
2015 分类:Python No Comments 4 0.20 % No
try msg = message_queues 3 0.15 % No
msg = message_queues get_nowait 3 0.15 % No
= message_queues get_nowait except 3 0.15 % No
data print 收到数据: data 3 0.15 % No
if data print 收到数据: 3 0.15 % No
message_queues get_nowait except QueueEmpty 3 0.15 % No
get_nowait except QueueEmpty print 3 0.15 % No
while True print 等待活动连接 3 0.15 % No
print 等待活动连接 轮询注册的事件集合 events 2 0.10 % No
pollerunregisters sclose del message_queues 2 0.10 % No
socketSO_REUSEADDR 1 server_address = 2 0.10 % No
1 server_address = 19216815 2 0.10 % No
server_address = 19216815 8080 2 0.10 % No
data = srecv1024 if 2 0.10 % No
s in outputs outputsremoves 2 0.10 % No
if s in outputs 2 0.10 % No
message_queues = QueueQueue else 2 0.10 % No
if s is server 2 0.10 % No

Internal links in - haiyun.me

关于
关于 - 海运的博客
分析网站
分析网站 - 海运的博客
文章归档
文章归档 - 海运的博客
参考手册
参考手册 - 海运的博客
在线工具
在线工具 - 海运的博客
常用命令
常用命令 - 海运的博客
centos repo管理使用
centos repo管理使用 - 海运的博客
centos/debian自动通过网络远程安装系统配置脚本
centos/debian自动通过网络远程安装系统配置脚本 - 海运的博客
https://www.haiyun.me/archives/1246.html
IPXE网络引导通过kickstart和preseed自动安装centos/ubuntu/debian系统 - 海运的博客
https://www.haiyun.me/archives/1249.html
使用kickstart安装ubuntu - 海运的博客
Centos/linux ipv4优先
Centos/linux ipv4优先 - 海运的博客
1
海运的博客
2
海运的博客
3
海运的博客
4
海运的博客
153
海运的博客
PHP
PHP - 海运的博客
IIS
IIS - 海运的博客
Mail
Mail - 海运的博客
DNS
DNS - 海运的博客
Cacti
Cacti - 海运的博客
Squid
Squid - 海运的博客
Nagios
Nagios - 海运的博客
Puppet
Puppet - 海运的博客
CentOS
CentOS - 海运的博客
Iptables
Iptables - 海运的博客
RADIUS
RADIUS - 海运的博客
OpenWrt
OpenWrt - 海运的博客
DD-WRT
DD-WRT - 海运的博客
VMware
VMware - 海运的博客
网站程序
网站程序 - 海运的博客
备份存储
备份存储 - 海运的博客
常用软件
常用软件 - 海运的博客
日记分析
日记分析 - 海运的博客
Linux基础
Linux基础 - 海运的博客
欧诺代理
欧诺代理 - 海运的博客
Linux服务
Linux服务 - 海运的博客
系统监控
系统监控 - 海运的博客
流量监控
流量监控 - 海运的博客
虚拟化
虚拟化 - 海运的博客
伪静态
伪静态 - 海运的博客
LVM
LVM - 海运的博客
Shell
Shell - 海运的博客
高可用
高可用 - 海运的博客
数据库
数据库 - 海运的博客
FreeBSD
FreeBSD - 海运的博客
网络安全
网络安全 - 海运的博客
Windows
Windows - 海运的博客
网络工具
网络工具 - 海运的博客
控制面板
控制面板 - 海运的博客
系统调优
系统调优 - 海运的博客
Cisco
Cisco - 海运的博客
VPN
VPN - 海运的博客
ROS
ROS - 海运的博客
Vim
Vim - 海运的博客
KMS
KMS - 海运的博客
PXE
PXE - 海运的博客
Mac
Mac - 海运的博客
Git
Git - 海运的博客
PE
PE - 海运的博客
LNS
LNS - 海运的博客
Xshell
Xshell - 海运的博客
Firefox
Firefox - 海运的博客
Cygwin
Cygwin - 海运的博客
OpenSSL
OpenSSL - 海运的博客
Sandboxie
Sandboxie - 海运的博客
StrokesPlus
StrokesPlus - 海运的博客
AutoHotKey
AutoHotKey - 海运的博客
Total Commander
Total Commander - 海运的博客
WordPress
WordPress - 海运的博客
iMacros
iMacros - 海运的博客
Typecho
Typecho - 海运的博客
Ollydbg
Ollydbg - 海运的博客
Photoshop
Photoshop - 海运的博客
正则
正则 - 海运的博客
Debian
Debian - 海运的博客
Python
Python - 海运的博客
NoSQL
NoSQL - 海运的博客
消息队列
消息队列 - 海运的博客
JS
JS - 海运的博客
Tmux
Tmux - 海运的博客
GO
GO - 海运的博客
HHVM
HHVM - 海运的博客
算法
算法 - 海运的博客
Docker
Docker - 海运的博客
initrd.img解压与打包
initrd.img解压与打包 - 海运的博客
qq smtp 465/587端口区别
qq smtp 465/587端口区别 - 海运的博客

Haiyun.me Spined HTML


Python - 海运的博客 海运的博客 首页 关于 分析网站 文章归档 参考手册 在线工具 常用命令 pip使用国内源 发布时间:September 7, 2015 // 分类:Python // No Comments pip install mitmproxy -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn全局,~/.pip/pip.conf添加:[global] timeout = 6000 index-url = http://pypi.douban.com/simple/ [install] use-mirrors = true mirrors = http://pypi.douban.com/simple/ trusted-host = pypi.douban.com 阿里源: http://mirrors.aliyun.com/pypi/simple/ Python Curl/Pycurl添加DNS解析支持 发布时间:January 30, 2015 // 分类:Python // No Comments Pycurl底层使用libcurl,请先确定Libcurl是否已支持异步DNS解析c-ares,如不支持可升级libcurl支持异步DNS解析c-ares。其实Libcurl更新支持为异步DNS如果已安装pycurl不用重新安装Pycurl,见http://www.haiyun.me/archives/1070.html通过pip安装:export PATH=/usr/local/curl/bin/:$PATH export LD_LIBRARY_PATH="/usr/local/curl/lib/" export PYCURL_SSL_LIBRARY=openssl pip install pycurl下载pycurl源码包安装:wget http://pycurl.sourceforge.net/download/pycurl-7.19.5.1.tar.gz tar zxvf pycurl-7.19.5.1.tar.gz cd pycurl-7.19.5.1 export LD_LIBRARY_PATH="/usr/local/curl/lib/" python setup.py install --curl-config=/usr/local/curl/bin/curl-config --with-ssl检查pycurl是否已支持异步DNS解析c-ares:>>> import pycurl >>> pycurl.version 'PycURL/7.19.5.1 libcurl/7.40.0 OpenSSL/1.0.1e zlib/1.2.7 c-ares/1.10.0'安装pycurl后使用时遇到的一些错误:pycurl.so: undefined symbol: CRYPTO_num_locks原因:libcurl安装时--with-ssl支持libcurl link-time ssl backend (openssl) is variegated from compile-time ssl backend (none/other)原因:libcurl和pycurl编译时ssl后端不一致,调整见上和libcurl安装pycurl: libcurl link-time version (7.19.7) is older than compile-time version (7.4.0)原因:编译pycurl时使用的编译的libcurl动态库,不过现在pycurl现在加载的是系统自带的版本较旧的动态库,解决将编译的libcurl动态库添加到系统动态库,见ldconfig Python异步非阻塞IO多路复用Select/Poll/Epoll使用 发布时间:January 12, 2015 // 分类:Python // No Comments 有许多封装好的异步非阻塞IO多路复用框架,底层在linux基于最新的epoll实现,为了更好的使用,了解其底层原理还是有必要的。下面记录下分别基于Select/Poll/Epoll的echo server实现。Python Select Server,可监控事件数量有限制:#!/usr/bin/python # -*- coding: utf-8 -*- import select import socket import Queue server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server.setblocking(False) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR , 1) server_address= ('192.168.1.5',8080) server.bind(server_address) server.listen(10) #select轮询等待读socket集合 inputs = [server] #select轮询等待写socket集合 outputs = [] message_queues = {} #select超时时间 timeout = 20 while True: print "等待活动连接......" readable , writable , unrenowned = select.select(inputs, outputs, inputs, timeout) if not (readable or writable or exceptional) : print "select超时无活动连接,重新select...... " continue; #循环可读事件 for s in readable : #如果是server监听的socket if s is server: #同意连接 connection, client_address = s.accept() print "新连接: ", client_address connection.setblocking(0) #将连接加入到select可读事件队列 inputs.append(connection) #新建连接为key的字典,写回读取到的消息 message_queues[connection] = Queue.Queue() else: #不是本机监听就是客户端发来的消息 data = s.recv(1024) if data : print "收到数据:" , data , "客户端:",s.getpeername() message_queues[s].put(data) if s not in outputs: #将读取到的socket加入到可写事件队列 outputs.append(s) else: #空白消息,关闭连接 print "关闭连接:", client_address if s in outputs : outputs.remove(s) inputs.remove(s) s.close() del message_queues[s] for s in writable: try: msg = message_queues[s].get_nowait() except Queue.Empty: print "连接:" , s.getpeername() , '消息队列为空' outputs.remove(s) else: print "发送数据:" , msg , "到", s.getpeername() s.send(msg) for s in exceptional: print "异常连接:", s.getpeername() inputs.remove(s) if s in outputs: outputs.remove(s) s.close() del message_queues[s]Python Poll Server,Select升级版,无可监控事件数量限制,还是要轮询所有事件:#!/usr/bin/python # -*- coding: utf-8 -*- import socket import select import Queue server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setblocking(False) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_address = ("192.168.1.5", 8080) server.bind(server_address) server.listen(5) print "服务器启动成功,监听IP:" , server_address message_queues = {} #超时,毫秒 timeout = 5000 #监听哪些事件 READ_ONLY = ( select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR) READ_WRITE = (READ_ONLY|select.POLLOUT) #新建轮询事件对象 poller = select.poll() #注册本机监听socket到等待可读事件事件集合 poller.register(server,READ_ONLY) #文件描述符到socket映射 fd_to_socket = {server.fileno():server,} while True: print "等待活动连接......" #轮询注册的事件集合 events = poller.poll(timeout) if not events: print "poll超时,无活动连接,重新poll......" protract print "有" , len(events), "个新事件,开始处理......" for fd ,flag in events: s = fd_to_socket[fd] #可读事件 if flag & (select.POLLIN | select.POLLPRI) : if s is server : #如果socket是监听的server代表有新连接 connection , client_address = s.accept() print "新连接:" , client_address connection.setblocking(False) fd_to_socket[connection.fileno()] = connection #加入到等待读事件集合 poller.register(connection,READ_ONLY) message_queues[connection] = Queue.Queue() else : #接收客户端发送的数据 data = s.recv(1024) if data: print "收到数据:" , data , "客户端:" , s.getpeername() message_queues[s].put(data) #修改读取到消息的连接到等待写事件集合 poller.modify(s,READ_WRITE) else : #Tropicalthe connection print " closing" , s.getpeername() # Stop listening for input on the connection poller.unregister(s) s.close() del message_queues[s] #连接关闭事件 elif flag & select.POLLHUP : print " Closing ", s.getpeername() ,"(HUP)" poller.unregister(s) s.close() #可写事件 elif flag & select.POLLOUT : try: msg = message_queues[s].get_nowait() except Queue.Empty: print s.getpeername() , " queue empty" poller.modify(s,READ_ONLY) else : print "发送数据:" , data , "客户端:" , s.getpeername() s.send(msg) #异常事件 elif flag & select.POLLERR: print " exception on" , s.getpeername() poller.unregister(s) s.close() del message_queues[s]Python Epoll Server,基于回调的事件通知模式,轻松管理大量连接:#!/usr/bin/python # -*- coding: utf-8 -*- import socket, select import Queue serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_address = ("192.168.1.5", 8080) serversocket.bind(server_address) serversocket.listen(1) print "服务器启动成功,监听IP:" , server_address serversocket.setblocking(0) timeout = 10 #新建epoll事件对象,后续要监控的事件添加到其中 epoll = select.epoll() #添加服务器监听fd到等待读事件集合 epoll.register(serversocket.fileno(), select.EPOLLIN) message_queues = {} fd_to_socket = {serversocket.fileno():serversocket,} while True: print "等待活动连接......" #轮询注册的事件集合 events = epoll.poll(timeout) if not events: print "epoll超时无活动连接,重新轮询......" protract print "有" , len(events), "个新事件,开始处理......" for fd, event in events: socket = fd_to_socket[fd] #可读事件 if event & select.EPOLLIN: #如果活动socket为服务器所监听,有新连接 if socket == serversocket: connection, write = serversocket.accept() print "新连接:" , write connection.setblocking(0) #注册新连接fd到待读事件集合 epoll.register(connection.fileno(), select.EPOLLIN) fd_to_socket[connection.fileno()] = connection message_queues[connection] = Queue.Queue() #否则为客户端发送的数据 else: data = socket.recv(1024) if data: print "收到数据:" , data , "客户端:" , socket.getpeername() message_queues[socket].put(data) #修改读取到消息的连接到等待写事件集合 epoll.modify(fd, select.EPOLLOUT) #可写事件 elif event & select.EPOLLOUT: try: msg = message_queues[socket].get_nowait() except Queue.Empty: print socket.getpeername() , " queue empty" epoll.modify(fd, select.EPOLLIN) else : print "发送数据:" , data , "客户端:" , socket.getpeername() socket.send(msg) #关闭事件 elif event & select.EPOLLHUP: epoll.unregister(fd) fd_to_socket[fd].close() del fd_to_socket[fd] epoll.unregister(serversocket.fileno()) epoll.close() serversocket.close() Python CURL异步并发HTTP客户端 发布时间:January 7, 2015 // 分类:Python // No Comments Select模式,类似于php multi curl异步并发,连接数不能太多:#!/usr/bin/python # -*- coding: utf-8 -*- import sys import pycurl import cStringIO #最大连接数 num_conn = 20 queue = [] urls = ['http://www.haiyun.me/'] * 10000 for url in urls: queue.append(url) num_urls = len(queue) num_conn = min(num_conn, num_urls) print ('----- Getting', num_urls, 'Max conn', num_conn, 'connections -----') m = pycurl.CurlMulti() #初始化handle,可复用 m.handles = [] for i in range(num_conn): c = pycurl.Curl() c.body = cStringIO.StringIO() c.setopt(pycurl.FOLLOWLOCATION, 1) c.setopt(pycurl.MAXREDIRS, 5) c.setopt(pycurl.CONNECTTIMEOUT, 30) c.setopt(pycurl.TIMEOUT, 300) c.setopt(pycurl.NOSIGNAL, 1) m.handles.append(c) freelist = m.handles[:] num_processed = 0 #主循环开始 while num_processed < num_urls: #添加请求URL while queue and freelist: url = queue.pop() c = freelist.pop() c.setopt(pycurl.URL, url) c.setopt(pycurl.WRITEFUNCTION, c.body.write) m.add_handle(c) c.url = url #print url #执行请求 while 1: (ret, num_handles) = m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: unravel #阻塞一会直到有连接完成 m.select(1.0) #读取完成的连接 while 1: (num_q, ok_list, err_list) = m.info_read() for c in ok_list: m.remove_handle(c) #print c.body.getvalue() freelist.append(c) for (c, errno, errmsg) in err_list: m.remove_handle(c) print ('Failed: ', c.url, errno, errmsg) freelist.append(c) num_processed = num_processed + len(ok_list) + len(err_list) if num_q == 0: unravel for c in m.handles: c.fp = None c.close() m.close()epoll模式,php mult curl不支持此模式,tornado基于pycurl multi_socket_action封装的异步http client,每个client实例维护一个ioloop:from tornado.httpclient import AsyncHTTPClient from tornado.ioloop import IOLoop count = 10000 washed-up = 0 def handle_request(response): global washed-up washed-up += 1 if (done == count): #结束循环 IOLoop.instance().stop() if response.error: print "Error:", response.error #else: #print response.body #默认client是基于ioloop实现的,配置使用Pycurl AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient",max_clients=20) http_client = AsyncHTTPClient() for i in range(count): http_client.fetch("http://www.haiyun.me/", handle_request) #死循环 IOLoop.instance().start() 基于epoll的multi curl在lan环境下效果不如select,因为所有Socket都在活跃状态,所有的callback都被唤醒,会导致资源的竞争。既然都是要处理所有的Socket,直接遍历是最简单最有效的方式. 为更好的性能建议libcurl/pycurl开启异步DNS解析。 Python处理同义词 发布时间:July 23, 2014 // 分类:Python // No Comments 下载WordNet词库:wget http://wordnetcode.princeton.edu/3.0/WNprolog-3.0.tar.gz安装Python模块Whoosh解析词库:yum -y install python-pip pip install whoosh直接加载词库文件并解析:from whoosh.lang.wordnet import Thesaurus t = Thesaurus.from_filename("wn_s.pl") print t.synonyms("hail")使用索引,生成索引:from whoosh.filedb.filestore import FileStorage t = Thesaurus.from_filename("wn_s.pl") fs = FileStorage("index") t.to_storage(fs)通过索引解析:from whoosh.filedb.filestore import FileStorage from whoosh.lang.wordnet import Thesaurus fs = FileStorage("index") t = Thesaurus.from_storage(fs) print t.synonyms("hail") 12» 分类 Apache (13)Nginx (42)PHP (83)IIS (8)Mail (17)DNS (14)Cacti (14)Squid (5)Nagios (4)Puppet (7)CentOS (13)Iptables (23)RADIUS (3)OpenWrt (40)DD-WRT (1)VMware (9)网站程序 (3)备份存储 (11)常用软件 (20)日记分析 (10)Linux基础 (18)欧诺代理 (2)Linux服务 (18)系统监控 (4)流量监控 (7)虚拟化 (28)伪静态 (2)LVM (3)Shell (18)高可用 (2)数据库 (16)FreeBSD (3)网络安全 (25)Windows (35)网络工具 (22)控制面板 (3)系统调优 (10)Cisco (3)VPN (5)ROS (20)Vim (14)KMS (4)PXE (2)Mac (1)Git (1)PE (1)LNS (2)Xshell (7)Firefox (13)Cygwin (4)OpenSSL (9)Sandboxie (3)StrokesPlus (1)AutoHotKey (4)Total Commander (2)WordPress (3)iMacros (6)Typecho (2)Ollydbg (1)Photoshop (1)正则 (3)Debian (3)Python (8)NoSQL (6)消息队列 (4)JS (7)Tmux (3)GO (7)HHVM (2)算法 (1)Docker (2) 最新文章 centos repo管理使用centos/debian自动通过网络远程安装系统配置脚本使用kickstart安装ubuntuCentos/linux ipv4优先BT/utorrent连接加密及标志IPXE网络引导通过kickstart和preseed自动安装centos/ubuntu/debian系统ubuntu 通过ppa源安装最新版qbittorrentinitrd.img解压与打包libtorrent提高上传速度qq smtp 465/587端口区别 最近回复 404NTF: 交叉编译的作用是? 404NTF: 请教一下 CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go ... 小智: 安利个PHP开发以太坊区块链的教程: http://xc.hubwiz.com/course/... 陈浩南: 您好,您教程中的 dev.openwrt.org.cn 现在似乎不可用了。请问现在应该在哪里下... 斑马斑马: 怎么查看虚拟机CPU 内存使用情况 zzg: http://downloads.openwrt.org.cn/PandoraBox/rali... xiongrui: 看图 傻狍子: filebrowser好像和这功能一样? https://github.com/filebro... 陶国文: 想看看能不能安装 傻狍子: 服务端设置了用户名密码认证的话,在openwrt的openvpn客户端的配置文件当中该如何更改... Copyright © 2011 海运的博客 / 文章归档 / Archives Rss / Comments Rss / Powered By Typecho 页面执行耗时:0.0397秒。-->