Skip to content

Commit

Permalink
Excepthook workaround is no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende authored and geigi committed Dec 6, 2023
1 parent 4d00351 commit 59fa533
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions cozy/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,6 @@
log = logging.getLogger("application")


def setup_thread_excepthook():
"""
Workaround for `sys.excepthook` thread bug from:
http://bugs.python.org/issue1230540
Call once from the main thread before creating any threads.
"""

init_original = threading.Thread.__init__

def init(self, *args, **kwargs):

init_original(self, *args, **kwargs)
run_original = self.run

def run_with_except_hook(*args2, **kwargs2):
try:
run_original(*args2, **kwargs2)
except Exception:
sys.excepthook(*sys.exc_info())

self.run = run_with_except_hook

threading.Thread.__init__ = init


class Application(Adw.Application):
ui: CozyUI
app_controller: AppController
Expand All @@ -61,9 +35,7 @@ def __init__(self, pkgdatadir: str):
GLib.setenv("PULSE_PROP_media.role", "music", True)
GLib.set_application_name("Cozy")

self.old_except_hook = sys.excepthook
sys.excepthook = self.handle_exception
setup_thread_excepthook()
threading.excepthook = self.handle_exception

def do_startup(self):
log.info(distro.linux_distribution(full_distribution_name=False))
Expand Down Expand Up @@ -95,14 +67,18 @@ def do_activate(self):
mpris = MPRIS(self)
mpris._on_current_changed()

def handle_exception(self, exc_type, exc_value, exc_traceback):
def handle_exception(self, _):
print("handle exception")

exc_type, exc_value, exc_traceback = sys.exc_info()

if exc_type is SystemExit:
return

try:
reporter.exception("uncaught", exc_value, "\n".join(format_exception(exc_type, exc_value, exc_traceback)))
except Exception:
None

self.old_except_hook(exc_type, exc_value, exc_traceback)
finally:
sys.excepthook(exc_type, exc_value, exc_traceback)

def quit(self):
self.app_controller.quit()
Expand Down

0 comments on commit 59fa533

Please sign in to comment.