本文整理汇总了Python中multiprocessing.util.log_to_stderr函数的典型用法代码示例。如果您正苦于以下问题:Python log_to_stderr函数的具体用法?Python log_to_stderr怎么用?Python log_to_stderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log_to_stderr函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_streamer_linecount
def test_streamer_linecount():
util.log_to_stderr(util.SUBDEBUG)
s = Streamer(processes=2)
stats = s.consume(range(10))
assert len(stats) == 5
# 0 is skipped.
assert stats[PROCESSING_TOTAL] == 10
assert stats[PROCESSING_SUCCESS] == 9
assert stats[PROCESSING_SKIPPED] == 1
assert stats[PROCESSING_ERROR] == 0
开发者ID:skitazaki,项目名称:python-clitool,代码行数:10,代码来源:processor_multi.py
示例2: prepare
def prepare(data):
"""
Try to get current process ready to unpickle process object
"""
old_main_modules.append(sys.modules['__main__'])
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process()._authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'main_path' in data:
main_path = data['main_path']
main_name = os.path.splitext(os.path.basename(main_path))[0]
main_name = main_name == '__init__' and os.path.basename(os.path.dirname(main_path))
if main_name != 'ipython':
import imp
if main_path is None:
dirs = None
elif os.path.basename(main_path).startswith('__init__.py'):
dirs = [os.path.dirname(os.path.dirname(main_path))]
else:
dirs = [os.path.dirname(main_path)]
if not main_name not in sys.modules:
raise AssertionError(main_name)
file, path_name, etc = imp.find_module(main_name, dirs)
try:
main_module = imp.load_module('__parents_main__', file, path_name, etc)
finally:
if file:
file.close()
sys.modules['__main__'] = main_module
main_module.__name__ = '__main__'
for obj in main_module.__dict__.values():
try:
if obj.__module__ == '__parents_main__':
obj.__module__ = '__main__'
except Exception:
pass
return
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:52,代码来源:forking.py
示例3: log_to_stderr
def log_to_stderr(level=None):
"""
Turn on logging and add a handler which prints to stderr
"""
from multiprocessing.util import log_to_stderr
return log_to_stderr(level)
开发者ID:vladistan,项目名称:py3k-__format__-sprint,代码行数:7,代码来源:__init__.py
示例4: prepare
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process().authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'log_fmt' in data:
import logging
util.get_logger().handlers[0].setFormatter(
logging.Formatter(data['log_fmt'])
)
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if hasattr(mp, 'set_start_method'):
mp.set_start_method('loky', force=True)
if 'tacker_pid' in data:
from . import semaphore_tracker
semaphore_tracker._semaphore_tracker._pid = data["tracker_pid"]
if 'init_main_from_name' in data:
_fixup_main_from_name(data['init_main_from_name'])
elif 'init_main_from_path' in data:
_fixup_main_from_path(data['init_main_from_path'])
开发者ID:as133,项目名称:scikit-learn,代码行数:45,代码来源:spawn.py
示例5: setup_logger
def setup_logger(loglevel=conf.CELERYD_LOG_LEVEL, logfile=None,
format=conf.CELERYD_LOG_FORMAT, **kwargs):
"""Setup the ``multiprocessing`` logger. If ``logfile`` is not specified,
``stderr`` is used.
Returns logger object.
"""
logger = get_default_logger(loglevel=loglevel)
if logger.handlers:
# Logger already configured
return logger
if logfile:
handler = logging.FileHandler
if hasattr(logfile, "write"):
handler = logging.StreamHandler
loghandler = handler(logfile)
formatter = logging.Formatter(format)
loghandler.setFormatter(formatter)
logger.addHandler(loghandler)
else:
from multiprocessing.util import log_to_stderr
log_to_stderr()
return logger
开发者ID:maximbo,项目名称:celery,代码行数:24,代码来源:log.py
示例6: prepare
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
old_main_modules.append(sys.modules['__main__'])
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process()._authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'main_path' in data:
# XXX (ncoghlan): The following code makes several bogus
# assumptions regarding the relationship between __file__
# and a module's real name. See PEP 302 and issue #10845
main_path = data['main_path']
main_name = os.path.splitext(os.path.basename(main_path))[0]
if main_name == '__init__':
main_name = os.path.basename(os.path.dirname(main_path))
if main_name == '__main__':
main_module = sys.modules['__main__']
main_module.__file__ = main_path
elif main_name != 'ipython':
# Main modules not actually called __main__.py may
# contain additional code that should still be executed
import imp
if main_path is None:
dirs = None
elif os.path.basename(main_path).startswith('__init__.py'):
dirs = [os.path.dirname(os.path.dirname(main_path))]
else:
dirs = [os.path.dirname(main_path)]
assert main_name not in sys.modules, main_name
file, path_name, etc = imp.find_module(main_name, dirs)
try:
# We would like to do "imp.load_module('__main__', ...)"
# here. However, that would cause 'if __name__ ==
# "__main__"' clauses to be executed.
main_module = imp.load_module(
'__parents_main__', file, path_name, etc
)
finally:
if file:
file.close()
sys.modules['__main__'] = main_module
main_module.__name__ = '__main__'
# Try to make the potentially picklable objects in
# sys.modules['__main__'] realize they are in the main
# module -- somewhat ugly.
for obj in list(main_module.__dict__.values()):
try:
if obj.__module__ == '__parents_main__':
obj.__module__ = '__main__'
except Exception:
pass
开发者ID:timm,项目名称:timmnix,代码行数:79,代码来源:forking.py
示例7: prepare
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
old_main_modules.append(sys.modules['__main__'])
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process()._authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'main_path' in data:
main_path = data['main_path']
main_name = os.path.splitext(os.path.basename(main_path))[0]
if main_name == '__init__':
main_name = os.path.basename(os.path.dirname(main_path))
if main_name != 'ipython':
import imp
if main_path is None:
dirs = None
elif os.path.basename(main_path).startswith('__init__.py'):
dirs = [os.path.dirname(os.path.dirname(main_path))]
else:
dirs = [os.path.dirname(main_path)]
assert main_name not in sys.modules, main_name
file, path_name, etc = imp.find_module(main_name, dirs)
try:
# We would like to do "imp.load_module('__main__', ...)"
# here. However, that would cause 'if __name__ ==
# "__main__"' clauses to be executed.
main_module = imp.load_module(
'__parents_main__', file, path_name, etc
)
finally:
if file:
file.close()
sys.modules['__main__'] = main_module
main_module.__name__ = '__main__'
# Try to make the potentially picklable objects in
# sys.modules['__main__'] realize they are in the main
# module -- somewhat ugly.
for obj in main_module.__dict__.values():
try:
if obj.__module__ == '__parents_main__':
obj.__module__ = '__main__'
except Exception:
pass
开发者ID:89sos98,项目名称:main,代码行数:71,代码来源:forking.py
示例8: as
if os.path.islink(logfile):
sys.exit('Logfile %s is a symlink. Exiting..' % logfile)
try:
logging.basicConfig(filename=logfile, level=level, format='%(asctime)s %(levelname)s %(funcName)s:%(lineno)d %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
os.chmod(logfile, 0600)
except IOError as (errno, strerror):
if errno == int('13'):
sys.exit('Error while writing to logfile: %s' % strerror)
try:
database = Database('yamls/', includes)
if len(database.issues) == 0:
sys.exit('Empty database. Exiting..')
# stderr to /dev/null
devnull_fd = open(os.devnull, "w")
sys.stderr = devnull_fd
log_to_stderr()
# Starts the asynchronous workers. Amount of workers is the same as cores in server.
# http://docs.python.org/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool
logging.debug('Starting workers.')
pool = Pool()
pool.apply_async(Worker, [arguments['--home'], post_process])
# Starts the actual populator daemon to get possible locations, which will be verified by workers.
# http://docs.python.org/library/multiprocessing.html#multiprocessing.Process
p = PopulateScanQueue()
if arguments['-r']:
logging.debug('Scanning recursively from path: %s', arguments['-r'])
populator = Process(target=p.populate, args=([arguments['-r']],))
elif arguments['--home']:
logging.debug('Scanning predefined variables: %s', arguments['--home'])
populator = Process(target=p.populate_predefined, args=(arguments['--home'], arguments['--check-modes'],))
else:
开发者ID:jannecederberg,项目名称:pyfiscan,代码行数:31,代码来源:pyfiscan.py
示例9: prepare
def prepare(data):
'''
Try to get current process ready to unpickle process object
'''
old_main_modules.append(sys.modules['__main__'])
if 'name' in data:
process.current_process().name = data['name']
if 'authkey' in data:
process.current_process()._authkey = data['authkey']
if 'log_to_stderr' in data and data['log_to_stderr']:
util.log_to_stderr()
if 'log_level' in data:
util.get_logger().setLevel(data['log_level'])
if 'sys_path' in data:
sys.path = data['sys_path']
if 'sys_argv' in data:
sys.argv = data['sys_argv']
if 'dir' in data:
os.chdir(data['dir'])
if 'orig_dir' in data:
process.ORIGINAL_DIR = data['orig_dir']
if 'main_path' in data:
# XXX (ncoghlan): The following code makes several bogus
# assumptions regarding the relationship between __file__
# and a module's real name. See PEP 302 and issue #10845
main_path = data['main_path']
main_name = os.path.splitext(os.path.basename(main_path))[0]
if main_name == '__init__':
main_name = os.path.basename(os.path.dirname(main_path))
if main_name == '__main__':
main_module = sys.modules['__main__']
main_module.__file__ = main_path
elif main_name != 'ipython':
# Main modules not actually called __main__.py may
# contain additional code that should still be executed
import imp
if main_path is None:
dirs = None
elif os.path.basename(main_path).startswith('__init__.py'):
dirs = [os.path.dirname(os.path.dirname(main_path))]
else:
dirs = [os.path.dirname(main_path)]
assert main_name not in sys.modules, main_name
sys.modules.pop('__mp_main__', None)
file, path_name, etc = imp.find_module(main_name, dirs)
try:
# We should not do 'imp.load_module("__main__", ...)'
# since that would execute 'if __name__ == "__main__"'
# clauses, potentially causing a psuedo fork bomb.
main_module = imp.load_module(
'__mp_main__', file, path_name, etc
)
finally:
if file:
file.close()
sys.modules['__main__'] = sys.modules['__mp_main__'] = main_module
开发者ID:Anzumana,项目名称:cpython,代码行数:69,代码来源:forking.py
示例10: parse_l
def parse_l(self, args):
""" Parse log-level and set it."""
log_to_stderr(args.loglevel)
开发者ID:pbattaglia,项目名称:distributed,代码行数:3,代码来源:parser.py
示例11: set
if __name__ == "__main__":
# load node id's that we have already processed
processed_ids = set()
try:
with open('results/processed_similarity_ids.txt') as file_in:
for line in file_in:
processed_ids.add(int(line))
except:
pass
# process the rest
nodes_to_process = [x for x in nodes_for_comparison if x not in processed_ids]
# parallel generation of results
util.log_to_stderr(util.SUBDEBUG)
n_cores = cpu_count()
chunksize = max(1, len(nodes_to_process) // (2 * (n_cores - 1)))
pool = Pool(processes=(n_cores - 1))
similarity_results = pool.imap(find_missing_edges,
nodes_to_process,
chunksize=chunksize)
# write results to file
with open('results/similarity_results.csv', 'a') as file_out, \
open('results/processed_similarity_ids.txt', 'a') as processed:
for result in similarity_results:
if not result:
continue
开发者ID:kevinsprong23,项目名称:buda-graph,代码行数:30,代码来源:similar_nodes.py
示例12: __init__
def __init__(self, processes=None, initializer=None, initargs=(),
maxtasksperchild=None, timeout_seconds=30):
log_to_stderr(level=DEBUG)
self._setup_queues()
self._taskqueue = Queue.Queue()
self._cache = {}
self._state = RUN
self._maxtasksperchild = maxtasksperchild
self._initializer = initializer
self._initargs = initargs
self._proc_num = 0
if processes is None:
try:
processes = cpu_count()
except NotImplementedError:
processes = 1
if initializer is not None and not hasattr(initializer, '__call__'):
raise TypeError('initializer must be a callable')
self._processes = processes
self._pool = []
self._repopulate_pool()
self._worker_handler = threading.Thread(
target=Pool._handle_workers,
args=(self, )
)
self._worker_handler.daemon = True
self._worker_handler._state = RUN
self._worker_handler.start()
self._task_handler = threading.Thread(
target=Pool._handle_tasks,
args=(self._taskqueue, self._quick_put, self._outqueue, self._pool)
)
self._task_handler.daemon = True
self._task_handler._state = RUN
self._task_handler.start()
self.timeout_seconds = timeout_seconds
self._result_handler = threading.Thread(
target=TimeoutPool._handle_results,
args=(self._outqueue, self._quick_get, self._cache, self._pool, self.timeout_seconds)
)
self._result_handler.daemon = True
self._result_handler._state = RUN
self._result_handler.start()
self._terminate = Finalize(
self, self._terminate_pool,
args=(self._taskqueue, self._inqueue, self._outqueue, self._pool,
self._worker_handler, self._task_handler,
self._result_handler, self._cache),
exitpriority=15
)
开发者ID:aelaguiz,项目名称:pyvotune,代码行数:62,代码来源:timeout_pool.py
示例13: prepare
def prepare(data):
"""
Try to get current process ready to unpickle process object
"""
old_main_modules.append(sys.modules["__main__"])
if "name" in data:
process.current_process().name = data["name"]
if "authkey" in data:
process.current_process()._authkey = data["authkey"]
if "log_to_stderr" in data and data["log_to_stderr"]:
util.log_to_stderr()
if "log_level" in data:
util.get_logger().setLevel(data["log_level"])
if "sys_path" in data:
sys.path = data["sys_path"]
if "sys_argv" in data:
sys.argv = data["sys_argv"]
if "dir" in data:
os.chdir(data["dir"])
if "orig_dir" in data:
process.ORIGINAL_DIR = data["orig_dir"]
if "main_path" in data:
# XXX (ncoghlan): The following code makes several bogus
# assumptions regarding the relationship between __file__
# and a module's real name. See PEP 302 and issue #10845
# The problem is resolved properly in Python 3.4+, as
# described in issue #19946
main_path = data["main_path"]
main_name = os.path.splitext(os.path.basename(main_path))[0]
if main_name == "__init__":
main_name = os.path.basename(os.path.dirname(main_path))
if main_name == "__main__":
# For directory and zipfile execution, we assume an implicit
# "if __name__ == '__main__':" around the module, and don't
# rerun the main module code in spawned processes
main_module = sys.modules["__main__"]
main_module.__file__ = main_path
elif main_name != "ipython":
# Main modules not actually called __main__.py may
# contain additional code that should still be executed
import imp
if main_path is None:
dirs = None
elif os.path.basename(main_path).startswith("__init__.py"):
dirs = [os.path.dirname(os.path.dirname(main_path))]
else:
dirs = [os.path.dirname(main_path)]
assert main_name not in sys.modules, main_name
file, path_name, etc = imp.find_module(main_name, dirs)
try:
# We would like to do "imp.load_module('__main__', ...)"
# here. However, that would cause 'if __name__ ==
# "__main__"' clauses to be executed.
main_module = imp.load_module("__parents_main__", file, path_name, etc)
finally:
if file:
file.close()
sys.modules["__main__"] = main_module
main_module.__name__ = "__main__"
# Try to make the potentially picklable objects in
# sys.modules['__main__'] realize they are in the main
# module -- somewhat ugly.
for obj in main_module.__dict__.values():
try:
if obj.__module__ == "__parents_main__":
obj.__module__ = "__main__"
except Exception:
pass
开发者ID:mozillazg,项目名称:pypy,代码行数:83,代码来源:forking.py
注:本文中的multiprocessing.util.log_to_stderr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论