• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LCA-ActivityBrowser / activity-browser / 10319203045

09 Aug 2024 12:27PM UTC coverage: 54.132% (-0.3%) from 54.397%
10319203045

push

github

web-flow
Merge pull request #1336 from mrvisscher/its_the_final_logger

Logging changes

136 of 164 new or added lines in 50 files covered. (82.93%)

68 existing lines in 2 files now uncovered.

8280 of 15296 relevant lines covered (54.13%)

0.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.68
/activity_browser/ui/threading.py
1
import sys
1✔
2
import threading
1✔
3
import logging
1✔
4

5
from activity_browser.mod import bw2data as bd
1✔
6
from activity_browser.logger import exception_hook
1✔
7

8
from PySide2.QtCore import QThread, SignalInstance, Signal
1✔
9

10

11
class ABThread(QThread):
1✔
12
    status: SignalInstance = Signal(int, str)
1✔
13

14
    def run(self):
1✔
15
        """Reimplemented from QThread to close any database connections before finishing."""
16
        # call run_safely and finish by closing the connections
17
        with SafeBWConnection(), InfoToSlot(self.status.emit):
×
18
            try:
×
19
                self.run_safely()
×
20
            except Exception as e:
×
21
                # pass exception to our except hook
22
                exception_hook(*sys.exc_info())
×
23
                raise e
×
24

25
    def run_safely(self):
1✔
26
        raise NotImplementedError
×
27

28

29
class SafeBWConnection:
1✔
30
    def __enter__(self):
1✔
31
        return
×
32

33
    def __exit__(self, *args):
1✔
34
        """
35
        Closes all connections for this thread
36
        """
37
        for _, SubstitutableDatabase in bd.config.sqlite3_databases:
×
38
            if not SubstitutableDatabase.db.is_closed():
×
39
                SubstitutableDatabase.db.close()
×
40

41

42
class InfoToSlot:
1✔
43
    def __init__(self, progress_slot=lambda progress, message: None):
1✔
44
        self.handler = LoggingProgressHandler("INFO")
×
45
        thread_local.progress_slot = progress_slot
×
46

47
    def __enter__(self):
1✔
48
        logging.root.addHandler(self.handler)
×
49
        return
×
50

51
    def __exit__(self, *args):
1✔
52
        logging.root.removeHandler(self.handler)
×
53
        return
×
54

55

56
class LoggingProgressHandler(logging.Handler):
1✔
57
    def filter(self, record: logging.LogRecord) -> bool:
1✔
UNCOV
58
        if record.thread != threading.get_ident():
×
59
            return False
×
UNCOV
60
        if record.levelname != "INFO":
×
61
            return False
×
UNCOV
62
        return True
×
63

64
    def emit(self, record: logging.LogRecord):
1✔
UNCOV
65
        try:
×
UNCOV
66
            thread_local.progress_slot(None, record.message)
×
UNCOV
67
        except AttributeError:
×
UNCOV
68
            pass
×
69

70

71
thread_local = threading.local()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc