: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)
| 14 | |
| 15 | |
| 16 | def 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 | |
| 63 | def _compute_filename_with_pid(target_file, pid=None): |
no test coverage detected