Python Ï̳߳صÄʵÏÖ
import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *
def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.xiaonei.com",
"qihoo":"http://www.qihoo.com",
"laohan":"http://www.laohan.org",
"eyou":"http://www.eyou.com",
"chinaren":"http://www.chinaren.com",
"douban":"http://www.douban.com",
"163":"http://www.163.com",
"daqi":"http://www.daqi.com",
"qq":"http://www.qq.com",
"baidu_1":"http://www.baidu.com/s?wd=asdfasdf",
"baidu_2":"http://www.baidu.com/s?wd=dddddddf",
"google_1":"http://www.baidu.com/s?wd=sadfas",
"google_2":"http://www.baidu.com/s?wd=sadflasd",
"hainei":"http://www.hainei.com",
"microsoft":"http://www.microsoft.com",
"wlzuojia":"http://www.wlzuojia.com"}
#ʹÓÃÏ̳߳Ø
socket.setdefaulttimeout(10)
print 'start testing'
wm = WorkerManager(50)
for url_name in url_list.keys():
wm.add_job(do_get_con, url_name, url_list[url_name])
wm.wait_for_complete()
print 'end testing'
def do_get_con(url_name,url_link):
try:
fd = urllib2.urlopen(url_link)
data = fd.read()
f_hand = open("/tmp/ttt/%s" % url_name,"w")
f_hand.write(data)
f_hand.close()
except Exception,e:
pass
if __name__ == "__main__":
main()
thread_poolµÄ´úÂ루·ÇÔ´´£¬×ª×Ô£ºhttp://blog.daviesliu.net/2006/10/09/234822/£©
import Queue, threading, sys
from threading import Thread
import time
import urllib
# working thread
class Worker(Thread):
worker_count = 0
timeout = 1
def __init__( self, workQueue, resultQueue, **kwds):
Thread._
Ïà¹ØÎĵµ£º
תÌû£º
http://blog.csdn.net/wyingquan/archive/2008/12/20/3561094.aspx
ÓÃpython×Ô´øµÄbinasciiÄ£¿é¼ÆËã×Ö·û´®µÄУÑéÂ룬³öÀ´µÄÊǸºÖµ£¬ÓëÓÃcдµÄ³ÌÐòµÃ³öµÄУÑéÂë²»Ò»Ñù£¬ËùÒÔ¾ÍÑо¿ÁËһϡ£·¢ÏÖ±ðÈËÓõÄpython3.0°æ±¾binasciiÄ£¿é¼ÆËã³öµÄcrc32УÑéÂëÊÇÎÒÏëÒªµÄ£¬Ã»°ì·¨Ö»ºÃ×Ô¼ºÓÃpythonʵÏÖÒ»ÏÂcrc32µÄËã·¨ÁË¡£·¢ ......
Python µÄÒì³£´¦Àí»úÖÆ
Python´úÂë
try:
raise Exception("a", "b")
except Exception,e:
print e
finally:
print "final"
('a', ......
import win32com.client
store = win32com.client.Dispatch('CAPICOM.Store')
# ´ò¿ªÖ¤Êé´æ´¢Çø
# 2 -> CAPICOM_CURRENT_USER_STORE
# 0 -> CAPICOM_STORE_OPEN_READ_ONLY
store.Open(2, "My", 0)
# ²éÕÒÓÐЧ֤Êé
# 12 -> CAPICOM_CERTIFICATE_FIND_KEY_USAGE
# 0x00000080 -> CAPICOM_DIGITAL_SIGNATU ......
Memcached
ÊÇdanga.com£¨ÔËÓªLiveJournalµÄ¼¼ÊõÍŶӣ©¿ª·¢µÄÒ»Ì×·Ö²¼Ê½ÄÚ´æ¶ÔÏ󻺴æϵͳ£¬ÓÃÓÚÔÚ¶¯Ì¬ÏµÍ³ÖмõÉÙÊý¾Ý¿â¸ºÔØ£¬ÌáÉýÐÔÄÜ¡£
ÍøÉÏÓкིܶµ½Memcached For LinuxµÄ°²×°½Ì³Ì£¬µ«ÊÇMemcached For Win32 and PythonµÄ¾ÍÉõÉÙ£¬Å¼¶ûgoogleÕÒµ½Ò»Æª
±È½ÏÏà½üµÄÓ¢ÎĽ̳̣¬¾õµÃ ......
Python ÊÇÃâ·ÑµÄ½âÊÍÐÔÓïÑÔ£¬¾ßÓÐÃæÏò¶ÔÏóµÄÌØÐÔ¡£¿ÉÒÔÔËÐÐÔÚ¶àÖÖ²Ù×÷ϵͳ֮ÉÏ£¬Python¾ßÓÐÇåÎúµÄ½á¹¹£¬¼ò½àµÄÓï·¨ÒÔ¼°Ç¿´óµÄ¹¦ÄÜ¡£Python¿ÉÒÔÍê³É´ÓÎı¾´¦Àíµ½ÍøÂçͨÐŵȸ÷ÖÖ¹¤×÷£¬python×ÔÉíÒѾÌṩÁË´óÁ¿µÄÄ£¿éÀ´ÊµÏÖ¸÷ÖÖ¹¦ÄÜ£¬³ý´ËÒÔÍ⻹¿ÉÒÔʹÓÃC/C++À´À©Õ¹Python£¬ÉõÖÁ»¹¿ÉÒÔ½«PythonǶÈëµ½ÆäËûÓ ......