MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / initialize_debug_stream

Function initialize_debug_stream

_pydev_bundle/pydev_log.py:16–60  ·  view source on GitHub ↗

:param bool reinitialize: Reinitialize is used to update the debug stream after a fork (thus, if it wasn't initialized, we don't need to do anything, just wait for the first regular log call to initialize).

(reinitialize=False)

Source from the content-addressed store, hash-verified

14
15
16def initialize_debug_stream(reinitialize=False):
17 """
18 :param bool reinitialize:
19 Reinitialize is used to update the debug stream after a fork (thus, if it wasn't
20 initialized, we don't need to do anything, just wait for the first regular log call
21 to initialize).
22 """
23 if reinitialize:
24 if not _LoggingGlobals._debug_stream_initialized:
25 return
26 else:
27 if _LoggingGlobals._debug_stream_initialized:
28 return
29
30 with _LoggingGlobals._initialize_lock:
31 # Initialization is done lazilly, so, it's possible that multiple threads try to initialize
32 # logging.
33
34 # Check initial conditions again after obtaining the lock.
35 if reinitialize:
36 if not _LoggingGlobals._debug_stream_initialized:
37 return
38 else:
39 if _LoggingGlobals._debug_stream_initialized:
40 return
41
42 _LoggingGlobals._debug_stream_initialized = True
43
44 # Note: we cannot initialize with sys.stderr because when forking we may end up logging things in 'os' calls.
45 _LoggingGlobals._debug_stream = NULL
46 _LoggingGlobals._debug_stream_filename = None
47
48 if not DebugInfoHolder.PYDEVD_DEBUG_FILE:
49 _LoggingGlobals._debug_stream = sys.stderr
50 else:
51 # Add pid to the filename.
52 try:
53 target_file = DebugInfoHolder.PYDEVD_DEBUG_FILE
54 debug_file = _compute_filename_with_pid(target_file)
55 _LoggingGlobals._debug_stream = open(debug_file, "w")
56 _LoggingGlobals._debug_stream_filename = debug_file
57 except Exception:
58 _LoggingGlobals._debug_stream = sys.stderr
59 # Don't fail when trying to setup logging, just show the exception.
60 traceback.print_exc()
61
62
63def _compute_filename_with_pid(target_file, pid=None):

Callers 2

_pydevd_logFunction · 0.85
_pydevd_log_exceptionFunction · 0.85

Calls 1

Tested by

no test coverage detected