Skip to content
Browse files

不要なファイルを削除

  • Loading branch information...
1 parent 48939d2 commit 3f67c7a76ad32e339eee233092981f738072603b @bluele committed Jan 29, 2012
Showing with 0 additions and 49 deletions.
  1. +0 −49 defferredurl.py
View
49 defferredurl.py
@@ -1,49 +0,0 @@
-# -*- coding: utf-8 -*-
-
-'''
->>> from defferredurl import DefferredUrl
->>> defferred = DefferredUrl()
->>> defferred.set("http://www.google.co.jp")
->>> # Any Process...
->>> content = defferred.get('http://www.google.co.jp')
-/* OR */ content = defferred['http://www.google.co.jp']
-'''
-
-from threading import Thread, Event
-import urllib2
-
-class DefferredUrl(list):
-
- def __init__(self):
- #self.pool = []
- self.ev = Event()
- self.urllist = {}
-
- def set(self, url):
- if self.urllist.has_key(url):
- return
- ev = Event()
- self.urllist[url] = {
- 'event':ev,
- 'content':None,
- }
- th = Thread(target=self._worker, args=(url, ev))
- #self.pool.append(th)
- th.daemon = True
- th.start()
-
- def get(self, url):
- self.urllist[url]['event'].wait()
- return self.urllist[url]['content']
-
- def _worker(self, url, ev):
- try:
- content = urllib2.urlopen(url)
- except:
- pass
- else:
- self.urllist[url]['content'] = content.read()
- ev.set()
-
- __getitem__ = get
-

0 comments on commit 3f67c7a

Please sign in to comment.
Something went wrong with that request. Please try again.