From 179db49d02eaa4d92d367000170e7fd70bf816d3 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 30 Dec 2016 12:24:22 -0500 Subject: Improved ad-hoc debug logger. --- coverage/debug.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'coverage/debug.py') diff --git a/coverage/debug.py b/coverage/debug.py index dff8beb..e75a895 100644 --- a/coverage/debug.py +++ b/coverage/debug.py @@ -8,6 +8,10 @@ import inspect import os import re import sys +try: + import _thread +except ImportError: + import thread as _thread from coverage.misc import isolate_module @@ -128,10 +132,17 @@ def dump_stack_frames(limit=None, out=None, skip=0): out.write("\n") +LOGGED_PROCESS = False + def log(msg, stack=False): # pragma: debugging """Write a log message as forcefully as possible.""" + global LOGGED_PROCESS with open("/tmp/covlog.txt", "a") as f: - f.write("{pid}: {msg}\n".format(pid=os.getpid(), msg=msg)) + if not LOGGED_PROCESS: + LOGGED_PROCESS = True + cmd = " ".join(getattr(sys, 'argv', ['???'])) + log("New process: executable %s, cmd: %s" % (sys.executable, cmd)) + f.write("{pid}.{tid}: {msg}\n".format(pid=os.getpid(), tid=_thread.get_ident(), msg=msg)) if stack: dump_stack_frames(out=f, skip=1) -- cgit v1.2.1