Python multiprocessing.get_logger() Examples
The following are 24
code examples of multiprocessing.get_logger().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
multiprocessing
, or try the search function
.
Example #1
Source File: BrundleFuzzServer.py From BrundleFuzz with MIT License | 7 votes |
def main(): """Starts several processes This must be kept to the bare minimum """ multiprocessing.log_to_stderr() logger = multiprocessing.get_logger() logger.setLevel(logging.INFO) jobs = [] try: bfs = BrundleFuzzServer() jobs.append(bfs) bfs.start() for j in jobs: j.join() except KeyboardInterrupt: pass
Example #2
Source File: process.py From green with MIT License | 6 votes |
def __call__(self, *args, **kwargs): try: result = self.__callable(*args, **kwargs) except Exception: # Here we add some debugging help. If multiprocessing's # debugging is on, it will arrange to log the traceback logger = multiprocessing.get_logger() if not logger.handlers: logger.addHandler(logging.StreamHandler()) logger.error(traceback.format_exc()) logger.handlers[0].flush() # Re-raise the original exception so the Pool worker can # clean up raise # It was fine, give a normal answer return result
Example #3
Source File: limit_function_call.py From pynisher with MIT License | 6 votes |
def __init__(self, mem_in_mb=None, cpu_time_in_s=None, wall_time_in_s=None, num_processes=None, grace_period_in_s = None, logger = None, capture_output=False): self.mem_in_mb = mem_in_mb self.cpu_time_in_s = cpu_time_in_s self.num_processes = num_processes self.wall_time_in_s = wall_time_in_s self.grace_period_in_s = 0 if grace_period_in_s is None else grace_period_in_s self.logger = logger if logger is not None else multiprocessing.get_logger() self.capture_output = capture_output if self.mem_in_mb is not None: self.logger.debug("Restricting your function to {} mb memory.".format(self.mem_in_mb)) if self.cpu_time_in_s is not None: self.logger.debug("Restricting your function to {} seconds cpu time.".format(self.cpu_time_in_s)) if self.wall_time_in_s is not None: self.logger.debug("Restricting your function to {} seconds wall time.".format(self.wall_time_in_s)) if self.num_processes is not None: self.logger.debug("Restricting your function to {} threads/processes.".format(self.num_processes)) if self.grace_period_in_s is not None: self.logger.debug("Allowing a grace period of {} seconds.".format(self.grace_period_in_s))
Example #4
Source File: logSetup.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getProcessSafeLogger(logPath): if multiprocessing.current_process().name == "MainProcess": return logging.getLogger(logPath) else: return multiprocessing.get_logger(logPath)
Example #5
Source File: node.py From crankycoin with MIT License | 5 votes |
def __init__(self, peers, api_client, blockchain, mempool, validator): super(FullNode, self).__init__(peers, api_client) mp.log_to_stderr() mp_logger = mp.get_logger() mp_logger.setLevel(logging.DEBUG) self.app = Bottle() self.app.merge(public_app) self.app.merge(permissioned_app) self.blockchain = blockchain self.mempool = mempool self.validator = validator
Example #6
Source File: miner.py From crankycoin with MIT License | 5 votes |
def __init__(self, blockchain, mempool): mp.log_to_stderr() mp_logger = mp.get_logger() mp_logger.setLevel(logging.DEBUG) self.blockchain = blockchain self.mempool = mempool
Example #7
Source File: logSetup.py From ChromeController with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getProcessSafeLogger(logPath): if multiprocessing.current_process().name == "MainProcess": return logging.getLogger(logPath) else: return multiprocessing.get_logger(logPath)
Example #8
Source File: _test_multiprocessing.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _test_level(cls, conn): logger = multiprocessing.get_logger() conn.send(logger.getEffectiveLevel())
Example #9
Source File: _test_multiprocessing.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_enable_logging(self): logger = multiprocessing.get_logger() logger.setLevel(util.SUBWARNING) self.assertTrue(logger is not None) logger.debug('this will not be printed') logger.info('nor will this') logger.setLevel(LOG_LEVEL)
Example #10
Source File: simple_task_queue_logging_separate_files.py From simple-task-queue with MIT License | 5 votes |
def create_logger(pid): logger = multiprocessing.get_logger() logger.setLevel(logging.INFO) fh = logging.FileHandler(f'logs/process_{pid}.log') fmt = '%(asctime)s - %(levelname)s - %(message)s' formatter = logging.Formatter(fmt) fh.setFormatter(formatter) logger.addHandler(fh) return logger
Example #11
Source File: simple_task_queue_logging.py From simple-task-queue with MIT License | 5 votes |
def create_logger(): logger = multiprocessing.get_logger() logger.setLevel(logging.INFO) fh = logging.FileHandler('process.log') fmt = '%(asctime)s - %(levelname)s - %(message)s' formatter = logging.Formatter(fmt) fh.setFormatter(formatter) logger.addHandler(fh) return logger
Example #12
Source File: HappyPacketProcess.py From happy with Apache License 2.0 | 5 votes |
def Sniffer(packetList, e): logger = multiprocessing.get_logger() snifferSocket = socket.socket( socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0003) ) snifferSocket.bind((options['interface'], 0)) logger.info("Sniffer and process packets, Press Ctrl-C to stop.") while True: packets = snifferSocket.recvfrom(65535) packet = packets[0] ethernetFrame = EthernetFrame() ethernetFrame.Decode(packet) if ethernetFrame.ethProto == 8: ipPacket = IPv4Packet() ipPacket.Decode(ethernetFrame.payload) if ipPacket.ipProtocol == 6: tcpPacket = TCPPacket() tcpPacket.Decode(ipPacket.payload) else: continue else: continue packetDic = MergeDicts(ethernetFrame.GetEthernetHeaderDic(), ipPacket.GetIpv4HeaderDic(), tcpPacket.GetTcpHeaderDic()) logger.debug(packetDic) snifferFilter = Filter(packetDic, options) if snifferFilter.run() is True: continue print packetDic packetList.append(packetDic) e.set() snifferSocket.close()
Example #13
Source File: _test_multiprocessing.py From ironpython3 with Apache License 2.0 | 5 votes |
def _test_level(cls, conn): logger = multiprocessing.get_logger() conn.send(logger.getEffectiveLevel())
Example #14
Source File: _test_multiprocessing.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_enable_logging(self): logger = multiprocessing.get_logger() logger.setLevel(util.SUBWARNING) self.assertTrue(logger is not None) logger.debug('this will not be printed') logger.info('nor will this') logger.setLevel(LOG_LEVEL)
Example #15
Source File: _test_multiprocessing.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _test_level(cls, conn): logger = multiprocessing.get_logger() conn.send(logger.getEffectiveLevel())
Example #16
Source File: _test_multiprocessing.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_enable_logging(self): logger = multiprocessing.get_logger() logger.setLevel(util.SUBWARNING) self.assertTrue(logger is not None) logger.debug('this will not be printed') logger.info('nor will this') logger.setLevel(LOG_LEVEL)
Example #17
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 5 votes |
def _test_level(cls, conn): logger = multiprocessing.get_logger() conn.send(logger.getEffectiveLevel())
Example #18
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_enable_logging(self): logger = multiprocessing.get_logger() logger.setLevel(util.SUBWARNING) self.assertTrue(logger is not None) logger.debug('this will not be printed') logger.info('nor will this') logger.setLevel(LOG_LEVEL)
Example #19
Source File: logging_pool.py From lichess-bot with GNU Affero General Public License v3.0 | 5 votes |
def error(msg, *args): return multiprocessing.get_logger().error(msg, *args)
Example #20
Source File: _test_multiprocessing.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_level(self): LEVEL1 = 32 LEVEL2 = 37 logger = multiprocessing.get_logger() root_logger = logging.getLogger() root_level = root_logger.level reader, writer = multiprocessing.Pipe(duplex=False) logger.setLevel(LEVEL1) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL1, reader.recv()) logger.setLevel(logging.NOTSET) root_logger.setLevel(LEVEL2) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL2, reader.recv()) root_logger.setLevel(root_level) logger.setLevel(level=LOG_LEVEL) # class _TestLoggingProcessName(BaseTestCase): # # def handle(self, record): # assert record.processName == multiprocessing.current_process().name # self.__handled = True # # def test_logging(self): # handler = logging.Handler() # handler.handle = self.handle # self.__handled = False # # Bypass getLogger() and side-effects # logger = logging.getLoggerClass()( # 'multiprocessing.test.TestLoggingProcessName') # logger.addHandler(handler) # logger.propagate = False # # logger.warn('foo') # assert self.__handled # # Check that Process.join() retries if os.waitpid() fails with EINTR #
Example #21
Source File: _test_multiprocessing.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def test_level(self): LEVEL1 = 32 LEVEL2 = 37 logger = multiprocessing.get_logger() root_logger = logging.getLogger() root_level = root_logger.level reader, writer = multiprocessing.Pipe(duplex=False) logger.setLevel(LEVEL1) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL1, reader.recv()) logger.setLevel(logging.NOTSET) root_logger.setLevel(LEVEL2) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL2, reader.recv()) root_logger.setLevel(root_level) logger.setLevel(level=LOG_LEVEL) # class _TestLoggingProcessName(BaseTestCase): # # def handle(self, record): # assert record.processName == multiprocessing.current_process().name # self.__handled = True # # def test_logging(self): # handler = logging.Handler() # handler.handle = self.handle # self.__handled = False # # Bypass getLogger() and side-effects # logger = logging.getLoggerClass()( # 'multiprocessing.test.TestLoggingProcessName') # logger.addHandler(handler) # logger.propagate = False # # logger.warn('foo') # assert self.__handled # # Check that Process.join() retries if os.waitpid() fails with EINTR #
Example #22
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 4 votes |
def test_main(run=None): if sys.platform.startswith("linux"): try: lock = multiprocessing.RLock() except OSError: raise unittest.SkipTest("OSError raises on RLock creation, see issue 3111!") check_enough_semaphores() if run is None: from test.support import run_unittest as run util.get_temp_dir() # creates temp directory for use by all processes multiprocessing.get_logger().setLevel(LOG_LEVEL) ProcessesMixin.pool = multiprocessing.Pool(4) ThreadsMixin.pool = multiprocessing.dummy.Pool(4) ManagerMixin.manager.__init__() ManagerMixin.manager.start() ManagerMixin.pool = ManagerMixin.manager.Pool(4) testcases = ( sorted(testcases_processes.values(), key=lambda tc:tc.__name__) + sorted(testcases_threads.values(), key=lambda tc:tc.__name__) + sorted(testcases_manager.values(), key=lambda tc:tc.__name__) + testcases_other ) loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases) # (ncoghlan): Whether or not sys.exc_clear is executed by the threading # module during these tests is at least platform dependent and possibly # non-deterministic on any given platform. So we don't mind if the listed # warnings aren't actually raised. with support.check_py3k_warnings( (".+__(get|set)slice__ has been removed", DeprecationWarning), (r"sys.exc_clear\(\) not supported", DeprecationWarning), quiet=True): run(suite) ThreadsMixin.pool.terminate() ProcessesMixin.pool.terminate() ManagerMixin.pool.terminate() ManagerMixin.manager.shutdown() del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
Example #23
Source File: test_multiprocessing.py From ironpython2 with Apache License 2.0 | 4 votes |
def test_level(self): LEVEL1 = 32 LEVEL2 = 37 logger = multiprocessing.get_logger() root_logger = logging.getLogger() root_level = root_logger.level reader, writer = multiprocessing.Pipe(duplex=False) logger.setLevel(LEVEL1) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL1, reader.recv()) logger.setLevel(logging.NOTSET) root_logger.setLevel(LEVEL2) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL2, reader.recv()) root_logger.setLevel(root_level) logger.setLevel(level=LOG_LEVEL) # class _TestLoggingProcessName(BaseTestCase): # # def handle(self, record): # assert record.processName == multiprocessing.current_process().name # self.__handled = True # # def test_logging(self): # handler = logging.Handler() # handler.handle = self.handle # self.__handled = False # # Bypass getLogger() and side-effects # logger = logging.getLoggerClass()( # 'multiprocessing.test.TestLoggingProcessName') # logger.addHandler(handler) # logger.propagate = False # # logger.warn('foo') # assert self.__handled # # Check that Process.join() retries if os.waitpid() fails with EINTR #
Example #24
Source File: _test_multiprocessing.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def test_level(self): LEVEL1 = 32 LEVEL2 = 37 logger = multiprocessing.get_logger() root_logger = logging.getLogger() root_level = root_logger.level reader, writer = multiprocessing.Pipe(duplex=False) logger.setLevel(LEVEL1) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL1, reader.recv()) logger.setLevel(logging.NOTSET) root_logger.setLevel(LEVEL2) p = self.Process(target=self._test_level, args=(writer,)) p.daemon = True p.start() self.assertEqual(LEVEL2, reader.recv()) root_logger.setLevel(root_level) logger.setLevel(level=LOG_LEVEL) # class _TestLoggingProcessName(BaseTestCase): # # def handle(self, record): # assert record.processName == multiprocessing.current_process().name # self.__handled = True # # def test_logging(self): # handler = logging.Handler() # handler.handle = self.handle # self.__handled = False # # Bypass getLogger() and side-effects # logger = logging.getLoggerClass()( # 'multiprocessing.test.TestLoggingProcessName') # logger.addHandler(handler) # logger.propagate = False # # logger.warn('foo') # assert self.__handled # # Check that Process.join() retries if os.waitpid() fails with EINTR #