MCPcopy Index your code
hub / github.com/python/cpython / do_queuehandler_configuration

Method do_queuehandler_configuration

Lib/test/test_logging.py:3953–3991  ·  view source on GitHub ↗
(self, qspec, lspec)

Source from the content-addressed store, hash-verified

3951 )
3952
3953 def do_queuehandler_configuration(self, qspec, lspec):
3954 cd = copy.deepcopy(self.config_queue_handler)
3955 fn = make_temp_file('.log', 'test_logging-cqh-')
3956 cd['handlers']['h1']['filename'] = fn
3957 if qspec is not None:
3958 cd['handlers']['ah']['queue'] = qspec
3959 if lspec is not None:
3960 cd['handlers']['ah']['listener'] = lspec
3961 qh = None
3962 try:
3963 self.apply_config(cd)
3964 qh = logging.getHandlerByName('ah')
3965 self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1'])
3966 self.assertIsNotNone(qh.listener)
3967 qh.listener.start()
3968 logging.debug('foo')
3969 logging.info('bar')
3970 logging.warning('baz')
3971
3972 # Need to let the listener thread finish its work
3973 while support.sleeping_retry(support.LONG_TIMEOUT,
3974 "queue not empty"):
3975 if qh.listener.queue.empty():
3976 break
3977
3978 # wait until the handler completed its last task
3979 qh.listener.queue.join()
3980
3981 with open(fn, encoding='utf-8') as f:
3982 data = f.read().splitlines()
3983 self.assertEqual(data, ['foo', 'bar', 'baz'])
3984 finally:
3985 if qh:
3986 qh.listener.stop()
3987 h = logging.getHandlerByName('h1')
3988 if h:
3989 self.addCleanup(closeFileHandler, h, fn)
3990 else:
3991 self.addCleanup(os.remove, fn)
3992
3993 @threading_helper.requires_working_threading()
3994 @support.requires_subprocess()

Callers 1

Calls 15

apply_configMethod · 0.95
make_temp_fileFunction · 0.85
assertIsNotNoneMethod · 0.80
addCleanupMethod · 0.80
openFunction · 0.50
assertEqualMethod · 0.45
startMethod · 0.45
debugMethod · 0.45
infoMethod · 0.45
warningMethod · 0.45
emptyMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected