本文整理汇总了Python中dispatcher.Dispatcher.join方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.join方法的具体用法?Python Dispatcher.join怎么用?Python Dispatcher.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.join方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stage
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import join [as 别名]
class Stage():
"""
A stage is a segment in a pipeline defining the type of workers it employs.
"""
def __init__(self, name, WorkerClass, num_workers, in_buffer,
out_buffer, seq_number, pipeline, path):
self.name = name
self.WorkerClass = WorkerClass
self.num_workers = num_workers
self.pipeline = pipeline
self.input = in_buffer
self.output = out_buffer
self.seq_number = seq_number
self.worker_environ = dict(pool=self, path=path)
self.isactive = False
self.progress = 0
def _create_worker(self, num):
return [ self.WorkerClass(self.input, self.output, i, **self.worker_environ) for i in range(num) ]
def add_worker(self):
new_worker = self._create_worker(1)
self.workers.append(new_worker)
self.num_workers += 1
def remove_worker(self):
self.workers.pop().join()
self.num_woker -= 1
def start(self):
# Global activity flag
self.isactive = True
# Dispatcher-controlled Event worker threads wait for before they start
self.wakeSignal = threading.Event()
# create worker threads
self.workers = self._create_worker(self.num_workers)
# create dispatcher thread
self.dispatcher = Dispatcher(self)
# start threads
[worker.start() for worker in self.workers]
# start dispatcher thread
self.dispatcher.start()
def stop(self):
"""
Block until all workers have finished current job. Input queue does not
have to be empty.
"""
self.isactive = False
self.dispatcher.join()
def join(self):
"""
Block until the input queue is empty.
"""
self.input.join()
self.isactive = False
self.dispatcher.join()
示例2: dispatch
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import join [as 别名]
def dispatch(resultfiles):
"""
Create dispatch semaphore and threads.
Join threads and returns dispatch status.
"""
threads = []
semaphore = threading.BoundedSemaphore(value=Configuration.semaphore)
for result in resultfiles:
expectfile = os.path.join(Configuration.expecteddir, result)
resultfile = os.path.join(Configuration.resultdir, result)
t = Dispatcher(result, expectfile, resultfile, result, semaphore)
t.start()
threads.append(t)
for t in threads:
t.join()
return(Dispatcher.get_pass(), Dispatcher.get_total())
示例3: Client
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import join [as 别名]
class Client(object):
INITIAL_TRACKERS=['udp://tracker.openbittorrent.com:80',
'udp://tracker.istole.it:80',
'udp://open.demonii.com:80',
'udp://tracker.coppersurfer.tk:80',
'udp://tracker.leechers-paradise.org:6969',
'udp://exodus.desync.com:6969',
'udp://tracker.publicbt.com:80']
VIDEO_EXTS={'.avi':'video/x-msvideo','.mp4':'video/mp4','.mkv':'video/x-matroska',
'.m4v':'video/mp4','.mov':'video/quicktime', '.mpg':'video/mpeg','.ogv':'video/ogg',
'.ogg':'video/ogg', '.webm':'video/webm', '.ts': 'video/mp2t', '.3gp':'video/3gpp'}
def __init__(self, url = None, port=None, ip=None, auto_shutdown=True, wait_time=20, timeout=5, auto_delete=True, temp_path=None, is_playing_fnc=None, print_status = False):
#server
if port:
self.port = port
else:
self.port = random.randint(8000,8099)
if ip:
self.ip = ip
else:
self.ip = "127.0.0.1"
self.server = Server((self.ip,self.port), Handler, client=self)
#Options
if temp_path:
self.temp_path = temp_path
else:
self.temp_path = os.path.join(os.path.dirname(__file__),"tmp")
self.is_playing_fnc = is_playing_fnc
self.timeout = timeout
self.auto_delete = auto_delete
self.wait_time= wait_time
self.auto_shutdown = auto_shutdown
self.buffer_size = 15
self.last_pieces_priorize = 5
self.state_file="state"
self.torrent_paramss={'save_path':self.temp_path,'storage_mode':lt.storage_mode_t.storage_mode_sparse}
#State
self.has_meta = False
self.meta = None
self.start_time = None
self.last_connect = 0
self.connected = False
self.closed = False
self.file = None
self.files = None
self._th=None
#Sesion
self._cache=Cache(self.temp_path)
self._ses=lt.session()
self._ses.listen_on(0,0)
#Cargamos el archivo de estado (si esxiste)
if os.path.exists(os.path.join(self.temp_path,self.state_file)):
try:
f = open(os.path.join(self.temp_path,self.state_file), "rb")
state=pickle.load(f)
self._ses.load_state(state)
f.close()
except:
pass
self._start_services()
#Monitor & Dispatcher
self._monitor= Monitor(self)
if print_status:
self._monitor.add_listener(self.print_status)
self._monitor.add_listener(self._check_meta)
self._monitor.add_listener(self.save_state)
self._monitor.add_listener(self.priorize_start_file)
self._monitor.add_listener(self.announce_torrent)
if self.auto_shutdown:
self._monitor.add_listener(self._auto_shutdown)
self._dispatcher=Dispatcher(self)
self._dispatcher.add_listener(self._update_ready_pieces)
#Iniciamos la URL
if url:
self.start_url(url)
def get_play_list(self):
"""
Función encargada de generar el playlist
"""
#Esperamos a lo metadatos
while not self.has_meta:
time.sleep(1)
#Comprobamos que haya archivos de video
#.........这里部分代码省略.........
示例4: Client
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import join [as 别名]
class Client(object):
INITIAL_TRACKERS=['udp://tracker.openbittorrent.com:80',
'udp://tracker.istole.it:80',
'udp://open.demonii.com:80',
'udp://tracker.coppersurfer.tk:80',
'udp://tracker.leechers-paradise.org:6969',
'udp://exodus.desync.com:6969',
'udp://tracker.publicbt.com:80']
VIDEO_EXTS={'.avi':'video/x-msvideo','.mp4':'video/mp4','.mkv':'video/x-matroska',
'.m4v':'video/mp4','.mov':'video/quicktime', '.mpg':'video/mpeg','.ogv':'video/ogg',
'.ogg':'video/ogg', '.webm':'video/webm', '.ts': 'video/mp2t', '.3gp':'video/3gpp'}
def __init__(self, url = None, port=None, ip=None, auto_shutdown=True, wait_time=20, timeout=5, auto_delete=True, temp_path=None, is_playing_fnc=None, print_status = False):
#server
self.port = port if port else random.randint(8000,8099)
self.ip = ip if ip else "127.0.0.1"
self.server = Server((self.ip,self.port), Handler, client=self)
#Options
self.temp_path = temp_path if temp_path else os.path.join(os.path.dirname(__file__),"tmp")
self.is_playing_fnc = is_playing_fnc
self.timeout = timeout
self.auto_delete = auto_delete
self.wait_time= wait_time
self.auto_shutdown = auto_shutdown
self.buffer_size = 10
self.state_file="state"
self.torrent_paramss={'save_path':self.temp_path,'storage_mode':lt.storage_mode_t.storage_mode_sparse}
#State
self.has_meta = False
self.meta = None
self.start_time = None
self.last_connect = 0
self.connected = False
self.closed = False
self.file = None
self.files = None
self._th=None
#Sesion
self._cache=Cache(self.temp_path)
self._ses=lt.session()
self._ses.listen_on(0,0)
#Cargamos el archivo de estado (si esxiste)
if os.path.exists(os.path.join(self.temp_path,self.state_file)):
try:
with open(os.path.join(self.temp_path,self.state_file), "rb") as f:
state=pickle.load(f)
self._ses.load_state(state)
except:
pass
self._start_services()
#Monitor & Dispatcher
self._monitor= Monitor(self)
if print_status:
self._monitor.add_listener(self.print_status)
self._monitor.add_listener(self._check_meta)
self._monitor.add_listener(self.save_state)
self._monitor.add_listener(self.priorize_start_file)
self._monitor.add_listener(self.announce_torrent)
if self.auto_shutdown:
self._monitor.add_listener(self._auto_shutdown)
self._dispatcher=Dispatcher(self)
self._dispatcher.add_listener(self._update_ready_pieces)
#Iniciamos la URL
if url:
self.start_url(url)
def get_play_list(self):
#Esperamos a lo metadatos
while not self.has_meta:
time.sleep(1)
#Comprobamos que haya archivos de video
if self.files:
if len(self.files) > 1:
return "http://" + self.ip + ":" + str(self.port) + "/playlist.pls"
else:
return "http://" + self.ip + ":" + str(self.port) + "/" + urllib.quote(self.files[0].path)
def get_files(self):
#Esperamos a lo metadatos
while not self.has_meta:
time.sleep(1)
files = []
#Comprobamos que haya archivos de video
if self.files:
#.........这里部分代码省略.........