设置超时,处理cookie,多线程
2014-07-05 17:20
471 查看
import socket import urllib from urllib import request import http.cookiejar import threading socket.setdefaulttimeout(10) cj = http.cookiejar.CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) lock = threading.Lock() def ThreadProc(n): if lock.acquire(): print(n) lock.release() class ThreadClass(threading.Thread): def __init__(self, n): threading.Thread.__init__(self) self.n = n def run(self): if lock.acquire(): print(self.n) lock.release() threads = [] for i in range(10): threads.append(threading.Thread(target = ThreadProc, args = (i,))) for i in threads: i.start() for i in threads: i.join() threads.clear() for i in range(10): threads.append(ThreadClass(i * 100)) for i in threads: i.start() for i in threads: i.join() threading.Semaphore(3) def Fn(n): print(n) threading.Timer(1, Fn, (n + 1,)).start() Fn(1)
相关文章推荐
- jQuery和ExtJS的timeOut超时设置和event事件处理
- jQuery的timeOut超时设置和event事件处理
- PHP file_get_contents设置超时处理方法
- Tornaodo 设置cookie超时(Expires)
- 多线程设置超时 测试端口是否打开
- JS设置COOKIE,PHP中处理
- apache axis 框架处理https请求时超时时间设置问题
- jQuery和ExtJS的timeOut超时设置和event事件处理
- Python脚本控制的WebDriver 常用操作 <二十八> 超时设置和cookie操作
- send和recv非阻塞时如何正确处理WSAEWOULDBLOCK和设置超时
- jQuery和ExtJS的timeOut超时设置和event事件处理
- SQL查询超时的设置方法(关于timeout的处理)
- SQL查询超时的设置方法(关于timeout的处理)
- httpClient请求超时的设置以及处理
- PHP file_get_contents设置超时处理方法
- jQuery 和ExtJS的timeOut超时设置和event事件处理
- jQuery和ExtJS的timeOut超时设置和event事件处理
- Python urllib2 设置超时时间并处理超时异常
- Httpclient对cookie的自动处理设置
- jQuery基于$.ajax设置移动端click超时处理方法