MCPcopy Create free account
hub / github.com/Delgan/loguru / test_safe_adding_while_logging

Function test_safe_adding_while_logging

tests/test_threading.py:53–82  ·  view source on GitHub ↗
(writer)

Source from the content-addressed store, hash-verified

51
52
53def test_safe_adding_while_logging(writer):
54 barrier = Barrier(2)
55 counter = itertools.count()
56
57 sink_1 = NonSafeSink(1)
58 sink_2 = NonSafeSink(1)
59 logger.add(sink_1, format="{message}", catch=False)
60
61 def thread_1():
62 barrier.wait()
63 logger.info("aaa{}bbb", next(counter))
64
65 def thread_2():
66 barrier.wait()
67 time.sleep(0.5)
68 logger.add(sink_2, format="{message}", catch=False)
69 logger.info("ccc{}ddd", next(counter))
70
71 threads = [Thread(target=thread_1), Thread(target=thread_2)]
72
73 for thread in threads:
74 thread.start()
75
76 for thread in threads:
77 thread.join()
78
79 logger.remove()
80
81 assert sink_1.written == "aaa0bbb\nccc1ddd\n"
82 assert sink_2.written == "ccc1ddd\n"
83
84
85def test_safe_removing_while_logging(capsys):

Callers

nothing calls this directly

Calls 4

NonSafeSinkClass · 0.85
addMethod · 0.80
startMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected