File: test_deadlock.py

package info (click to toggle)
logbook 1.7.0-1.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,140 kB
  • sloc: python: 6,558; makefile: 141
file content (36 lines) | stat: -rw-r--r-- 928 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys

import logbook


class MyObject:
    def __init__(self, logger_func):
        self._logger_func = logger_func

    def __str__(self):
        self._logger_func("this debug message produced in __str__")
        return "<complex object>"


class FakeLock:
    def __init__(self):
        self._acquired = False
        self._deadlock_occurred = False

    def acquire(self):
        if self._acquired:
            self._deadlock_occurred = True
        self._acquired = True

    def release(self):
        self._acquired = False


def test_deadlock_in_emit():
    logbook_logger = logbook.Logger("logbook")
    obj = MyObject(logbook_logger.info)
    stream_handler = logbook.StreamHandler(stream=sys.stderr, level=logbook.DEBUG)
    stream_handler.lock = FakeLock()
    with stream_handler.applicationbound():
        logbook_logger.info("format this: {}", obj)
    assert not stream_handler.lock._deadlock_occurred