<s> '''<STR_LIT>''' <EOL> import Queue as queue_module <EOL> import sys <EOL> from python_toolbox import caching <EOL> from python_toolbox import import_tools <EOL> def is_multiprocessing_queue ( queue ) : <EOL> '''<STR_LIT>''' <EOL> return queue . __module__ . startswith ( '<STR_LIT>' ) <EOL> def dump ( queue ) : <EOL> '''<STR_LIT>''' <EOL> return list ( iterate ( queue ) ) <EOL> def iterate ( queue , block = False , limit_to_original_size = False , <EOL> _prefetch_if_no_qsize = False ) : <EOL> '''<STR_LIT>''' <EOL> if limit_to_original_size : <EOL> if is_multiprocessing_queue ( queue ) and not _platform_supports_multiprocessing_qsize ( ) : <EOL> if _prefetch_if_no_qsize : <EOL> for item in dump ( queue ) : <EOL> yield item <EOL> return <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> for _ in xrange ( queue . qsize ( ) ) : <EOL> try : <EOL> yield queue . get ( block = block ) <EOL> except queue_module . Empty : <EOL> return <EOL> else : <EOL> while True : <EOL> try : <EOL> yield queue . get ( block = block ) <EOL> except queue_module . Empty : <EOL> return <EOL> def get_item ( queue , i ) : <EOL> '''<STR_LIT>''' <EOL> with queue . mutex : <EOL> return queue . queue [ i ] <EOL> def queue_as_list ( queue ) : <EOL> '''<STR_LIT>''' <EOL> with queue . mutex : <EOL> return list ( queue . queue ) <EOL> @ caching . cache ( ) <EOL> def _platform_supports_multiprocessing_qsize ( ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' not in sys . modules : <EOL> if not import_tools . exists ( '<STR_LIT>' ) : <EOL> return False <EOL> import multiprocessing <EOL> multiprocessing_queue = multiprocessing . Queue ( ) <EOL> try : <EOL> multiprocessing_queue . qsize ( ) <EOL> except NotImplementedError : <EOL> return False <EOL> else : <EOL> return True </s>
