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

Method test_race

Lib/test/test_logging.py:701–742  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

699 @threading_helper.requires_working_threading()
700 @support.requires_resource('walltime')
701 def test_race(self):
702 # Issue #14632 refers.
703 def remove_loop(fname, tries):
704 for _ in range(tries):
705 try:
706 os.unlink(fname)
707 self.deletion_time = time.time()
708 except OSError:
709 pass
710 time.sleep(0.004 * random.randint(0, 4))
711
712 del_count = 500
713 log_count = 500
714
715 self.handle_time = None
716 self.deletion_time = None
717
718 for delay in (False, True):
719 fn = make_temp_file('.log', 'test_logging-3-')
720 remover = threading.Thread(target=remove_loop, args=(fn, del_count))
721 remover.daemon = True
722 remover.start()
723 h = logging.handlers.WatchedFileHandler(fn, encoding='utf-8', delay=delay)
724 f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
725 h.setFormatter(f)
726 try:
727 for _ in range(log_count):
728 time.sleep(0.005)
729 r = logging.makeLogRecord({'msg': 'testing' })
730 try:
731 self.handle_time = time.time()
732 h.handle(r)
733 except Exception:
734 print('Deleted at %s, '
735 'opened at %s' % (self.deletion_time,
736 self.handle_time))
737 raise
738 finally:
739 remover.join()
740 h.close()
741 if os.path.exists(fn):
742 os.unlink(fn)
743
744 # The implementation relies on os.register_at_fork existing, but we test
745 # based on os.fork existing because that is what users and this test use.

Callers

nothing calls this directly

Calls 10

startMethod · 0.95
joinMethod · 0.95
make_temp_fileFunction · 0.85
setFormatterMethod · 0.80
sleepMethod · 0.45
timeMethod · 0.45
handleMethod · 0.45
closeMethod · 0.45
existsMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected