summaryrefslogtreecommitdiff
path: root/coverage/debug.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-30 12:24:22 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-30 12:24:22 -0500
commit88d50e9207e01c0e7561d272e52844bbe81eaea6 (patch)
tree9b032c341351bd3fe6230cc7bc6bd67258b1623e /coverage/debug.py
parent308fc8a6b1a6481a143964d89ac167cfa1f76005 (diff)
downloadpython-coveragepy-git-88d50e9207e01c0e7561d272e52844bbe81eaea6.tar.gz
Improved ad-hoc debug logger.
Diffstat (limited to 'coverage/debug.py')
-rw-r--r--coverage/debug.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index dff8beba..e75a895e 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)