xpra icon
Bug tracker and wiki

Ticket #1943: exitfunc.patch

File exitfunc.patch, 4.4 KB (added by Antoine Martin, 2 years ago)

patch to try to debug exitfunc / atexit behaviour

  • xpra/log.py

     
    44# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
    55# later version. See the file COPYING for details.
    66
     7import traceback
     8traceback.print_stack()
     9
    710import os
    811import sys
    912import logging
  • xpra/scripts/main.py

     
    77# later version. See the file COPYING for details.
    88
    99import sys
     10import atexit
     11saved_register = atexit.register
     12print("sys.exitfunc=%s" % (sys.exitfunc,))
     13exithandlers = getattr(atexit, "_exithandlers", [])
     14print("exithandlers=%s", exithandlers)
     15for x in exithandlers:
     16    import inspect
     17    try:
     18        print("%s: file=%s", x, inspect.getfile(x))
     19    except TypeError:
     20        pass
     21    try:
     22        print("%s: module=%s", x, inspect.getmodule(x))
     23    except TypeError:
     24        pass
     25def register(fn, *args, **kwargs):
     26    print("register(%s, %s, %s)" % (fn, args, kwargs))
     27    import traceback
     28    traceback.print_stack()
     29    saved_register(fn, *args, **kwargs)
     30atexit.register = register
     31
     32import sys
    1033import os.path
    1134import stat
    1235import socket
  • xpra/scripts/server.py

     
    88#  http://lists.partiwm.org/pipermail/parti-discuss/2008-September/000041.html
    99#  http://lists.partiwm.org/pipermail/parti-discuss/2008-September/000042.html
    1010# (also do not import anything that imports gtk)
     11
     12
    1113import subprocess
    1214import sys
    1315import os.path
    14 import atexit
    1516import signal
    1617import socket
    17 import traceback
    1818
    1919from xpra.scripts.main import info, warn, error, no_gtk, validate_encryption, parse_env, configure_env
    2020from xpra.scripts.config import InitException, TRUE_OPTIONS, FALSE_OPTIONS
     
    2828    global _cleanups
    2929    cleanups = _cleanups
    3030    _cleanups = []
    31     for c in cleanups:
     31    log = get_util_logger()
     32    log("run_cleanups() will run %s", cleanups)
     33    for fn, args, kwargs in cleanups:
    3234        try:
    33             c()
     35            log("calling %s", fn)
     36            fn(*args, **kwargs)
    3437        except:
    35             print("error running cleanup %s" % c)
    36             traceback.print_exception(*sys.exc_info())
     38            log.error("Error running cleanup %s", fn, exc_info=True)
    3739
    3840_when_ready = []
    3941
     
    4042def add_when_ready(f):
    4143    _when_ready.append(f)
    4244
    43 def add_cleanup(f):
    44     _cleanups.append(f)
     45def add_cleanup(f, *args, **kwargs):
     46    _cleanups.append((f, args, kwargs))
    4547
    46 def insert_cleanup(f):
    47     _cleanups.insert(0, f)
     48def insert_cleanup(f, *args, **kwargs):
     49    _cleanups.insert(0, (f, args, kwargs))
    4850
    4951
    5052def deadly_signal(signum, _frame):
     
    458460    if not shadowing and not proxying and not upgrading and opts.exit_with_children and not opts.start_child:
    459461        error_cb("--exit-with-children specified without any children to spawn; exiting immediately")
    460462
     463    import atexit
    461464    atexit.register(run_cleanups)
    462465
    463466    # Generate the script text now, because os.getcwd() will
     
    11421145        else:
    11431146            log.info("upgrading: not cleaning up Xvfb")
    11441147        r = 0
    1145     log("cleanups=%s", _cleanups)
     1148    log.info("cleanups=%s", _cleanups)
     1149    log.info("sys.exitfunc=%s", sys.exitfunc)
     1150    exithandlers = getattr(atexit, "_exithandlers", [])
     1151    log.info("exithandlers=%s", exithandlers)
     1152    for fn, args, kwargs in exithandlers:
     1153        import inspect
     1154        try:
     1155            log.info("%s: file=%s", fn, inspect.getfile(fn))
     1156        except TypeError:
     1157            pass
     1158        try:
     1159            log.info("%s: module=%s", fn, inspect.getmodule(fn))
     1160        except TypeError:
     1161            pass
     1162        if fn!=run_cleanups:
     1163            add_cleanup(fn, *args, **kwargs)
     1164    #atexit._exithandlers = [run_cleanups, [], {}]
     1165    #atexit._exithandlers = exithandlers[1:]
     1166    #atexit._exithandlers[:] = []
     1167    def myexit():
     1168        print("myexit")
     1169        for i, x in enumerate(exithandlers):
     1170            print("%i : %s" % (i, x,))
    11461171    try:
     1172        sys.exitfunc()
     1173    except:
     1174        log.error("exit func", exc_info=True)
     1175    #sys.exitfunc = myexit
     1176    log.info("sys.exitfunc=%s", sys.exitfunc)
     1177    try:
    11471178        return r
    11481179    finally:
    11491180        import gc