Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecursionError when trying to print/debug Track objects #831

Closed
sglvladi opened this issue Jul 27, 2023 · 0 comments · Fixed by #832
Closed

RecursionError when trying to print/debug Track objects #831

sglvladi opened this issue Jul 27, 2023 · 0 comments · Fixed by #832
Assignees
Labels

Comments

@sglvladi
Copy link
Collaborator

sglvladi commented Jul 27, 2023

When trying to print StoneSoup objects that recursively contain a large number of other objects (e.g. Tracks), or debugging scripts that contain such objects, a RecursionError is thrown, e.g.:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2023.1\plugins\python\helpers\pydev\pydevd.py", line 2195, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm 2023.1\plugins\python\helpers\pydev\pydevd.py", line 2177, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm 2023.1\plugins\python\helpers\pydev\pydevd.py", line 1489, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "C:\Program Files\JetBrains\PyCharm 2023.1\plugins\python\helpers\pydev\pydevd.py", line 1496, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2023.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\examples\recursion_error_example.py", line 153, in <module>
    print(track)
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\stonesoup\base.py", line 457, in __repr__
    rep = Base._repr.whitespace_remove(max_len_whitespace, value)
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\stonesoup\base.py", line 248, in whitespace_remove
    return cls.whitespace_remove(maxlen_whitespace, val)
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\stonesoup\base.py", line 248, in whitespace_remove
    return cls.whitespace_remove(maxlen_whitespace, val)
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\stonesoup\base.py", line 248, in whitespace_remove
    return cls.whitespace_remove(maxlen_whitespace, val)
  [Previous line repeated 986 more times]
  File "C:\Users\sglvladi\Workspace\GitHub\Stone-Soup-tmp\stonesoup\base.py", line 239, in whitespace_remove
    @classmethod
RecursionError: maximum recursion depth exceeded while calling a Python object

This seems to happen because of a recursive call to the BaseRepr.whitespace_remove() method (see here).

A script that demonstrates this error can be found here.

@sglvladi sglvladi added the bug label Jul 27, 2023
@orosoman-dstl orosoman-dstl self-assigned this Jul 28, 2023
sdhiscocks added a commit that referenced this issue Aug 7, 2023
Fix recursion error when printing objects

Fixes #831
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants