def test_logging_proxy(self): logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False) with mock.wrap_logger(logger) as sio: p = LoggingProxy(logger, loglevel=logging.ERROR) p.close() p.write('foo') assert 'foo' not in sio.getvalue() p.closed = False p.write('foo') assert 'foo' in sio.getvalue() lines = ['baz', 'xuzzy'] p.writelines(lines) for line in lines: assert line in sio.getvalue() p.flush() p.close() assert not p.isatty() with mock.stdouts() as (stdout, stderr): with in_sighandler(): p.write('foo') assert stderr.getvalue()
def test_logging_proxy(self): with restore_logging(): logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False) with wrap_logger(logger) as sio: p = LoggingProxy(logger, loglevel=logging.ERROR) p.close() p.write('foo') self.assertNotIn('foo', sio.getvalue()) p.closed = False p.write('foo') self.assertIn('foo', sio.getvalue()) lines = ['baz', 'xuzzy'] p.writelines(lines) for line in lines: self.assertIn(line, sio.getvalue()) p.flush() p.close() self.assertFalse(p.isatty()) with override_stdouts() as (stdout, stderr): with in_sighandler(): p.write('foo') self.assertTrue(stderr.getvalue())
def rdb_handler(*args): """Signal handler setting a rdb breakpoint at the current frame.""" with in_sighandler(): from celery.contrib.rdb import set_trace, _frame # gevent does not pass standard signal handler args frame = args[1] if args else _frame().f_back set_trace(frame)
def rdb_handler(*args): """Signal handler setting a rdb breakpoint at the current frame.""" with in_sighandler(): _, frame = args from celery.contrib import rdb rdb.set_trace(frame)
def test_patches(self): _patch_logger_class() self.assertTrue(logging.getLoggerClass()._signal_safe) _patch_logger_class() self.assertTrue(logging.getLoggerClass()._signal_safe) with in_sighandler(): logging.getLoggerClass().log(get_logger('test'))
def _handle_request(*args): with in_sighandler(): from celery.worker import state if current_process()._name == "MainProcess": if callback: callback(worker) safe_say("worker: {0} shutdown (MainProcess)".format(how)) if active_thread_count() > 1: setattr(state, {"Warm": "should_stop", "Cold": "should_terminate"}[how], exitcode) else: raise exc(exitcode)
def _handle_request(*args): with in_sighandler(): from celery.worker import state if current_process()._name == 'MainProcess': if callback: callback(worker) safe_say('worker: {0} shutdown (MainProcess)'.format(how)) if active_thread_count() > 1: setattr(state, {'Warm': 'should_stop', 'Cold': 'should_terminate'}[how], exitcode) else: raise exc(exitcode)
def _handle_request(*args): with in_sighandler(): from celery.worker import state if current_process()._name == 'MainProcess': if callback: callback(worker) safe_say(f'worker: {how} shutdown (MainProcess)') signals.worker_shutting_down.send( sender=worker.hostname, sig=sig, how=how, exitcode=exitcode, ) if active_thread_count() > 1: setattr(state, {'Warm': 'should_stop', 'Cold': 'should_terminate'}[how], exitcode) else: raise exc(exitcode)
def _handle_request(*args): with in_sighandler(): from celery.worker import state if current_process()._name == "MainProcess": if callback: callback(worker) safe_say("worker: {0} shutdown (MainProcess)".format(how)) signals.worker_shutting_down.send( sender=worker.hostname, sig=sig, how=how, exitcode=exitcode, ) if active_thread_count() > 1: setattr( state, {"Warm": "should_stop", "Cold": "should_terminate"}[how], exitcode, ) else: raise exc(exitcode)
def test_logging_proxy_bytes(self, restore_logging): logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False) with conftest.wrap_logger(logger) as sio: p = LoggingProxy(logger, loglevel=logging.ERROR) p.close() p.write(b'foo') assert 'foo' not in str(sio.getvalue()) p.closed = False p.write(b'\n') assert str(sio.getvalue()) == '' write_res = p.write(b'foo ') assert str(sio.getvalue()) == 'foo \n' assert write_res == 4 p.flush() p.close() assert not p.isatty() with conftest.stdouts() as (stdout, stderr): with in_sighandler(): p.write(b'foo') assert stderr.getvalue()
def test_logging_proxy(self): logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False) with mock.wrap_logger(logger) as sio: p = LoggingProxy(logger, loglevel=logging.ERROR) p.close() p.write("foo") self.assertNotIn("foo", sio.getvalue()) p.closed = False p.write("foo") self.assertIn("foo", sio.getvalue()) lines = ["baz", "xuzzy"] p.writelines(lines) for line in lines: self.assertIn(line, sio.getvalue()) p.flush() p.close() self.assertFalse(p.isatty()) with mock.stdouts() as (stdout, stderr): with in_sighandler(): p.write("foo") self.assertTrue(stderr.getvalue())
def warn_on_HUP_handler(signum, frame): with in_sighandler(): safe_say('{sig} not supported: Restarting with {sig} is ' 'unstable on this platform!'.format(sig=sig))
def test_patches(self): ensure_process_aware_logger() with in_sighandler(): logging.getLoggerClass().log(get_logger('test'))
def cry_handler(*args): """Signal handler logging the stacktrace of all active threads.""" with in_sighandler(): safe_say(cry())