Skip to content

Timeout does not detect debugger and times out during debugging session #109

@apacha

Description

@apacha

With version 2.0.0 a debugger-detection was implemented that allows developers to debug without time-limits. However, the detection of whether a debugger is attached or not does not work as expected, and I'm still getting timeouts in PyCharm when debugging, even after upgrading to 2.0.1.

I've played around and found this thread: https://stackoverflow.com/a/38637774/448357, which shows a way how the debugger-detection for PyCharm works. Basically:

import sys

gettrace = getattr(sys, 'gettrace', None)

if gettrace is None:
    print('No sys.gettrace - no debugger. Use normal timeout')
elif gettrace():
    print('Debugger found - disable timeout to enable debugging')
else:
    print("No Debugger - Use normal timeout")

Would it be possible to extend the mechanism to include this, in order to correctly disable timeouts when debugging with PyCharm?

Upon further investigation it seems like the known debuggers should either be extended or the mechanism should be made more flexible:

Screenshot 2021-10-18 at 11 56 01

How about:

KNOWN_DEBUGGING_MODULES = {"pydevd", "bdb", "pydevd_frame_evaluator"}
trace_func = None
if trace_func is None:
    trace_func = sys.gettrace()
if trace_func and inspect.getmodule(trace_func):
    parts = inspect.getmodule(trace_func).__name__.split(".")
    for name in KNOWN_DEBUGGING_MODULES:
        for part in parts:
            if name in part:
                return True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions