Skip to content

Max recursion errors for mathtext on Python 3.6 / OSX #7799

Closed

Description

@matthew-brett

See: MacPython/matplotlib-wheels#3

Errors occur testing 1.5.3 and current v2.x branch on Python 3.6, OSX.

======================================================================
ERROR: matplotlib.tests.test_mathtext.test_mathtext_cm_53.test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/matplotlib/testing/decorators.py", line 53, in failer
    result = f(*args, **kwargs)
  File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/matplotlib/testing/decorators.py", line 207, in do_test
    figure.savefig(actual_fname, **self._savefig_kwarg)
  File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/matplotlib/figure.py", line 1563, in savefig

[snip]

 File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/pyparsing.py", line 1510, in _parseCache
    value = cache.get(lookup)
  File "/Users/travis/build/MacPython/matplotlib-wheels/venv/lib/python3.6/site-packages/pyparsing.py", line 1459, in get
    return cache.get(key, not_in_cache)
RecursionError: maximum recursion depth exceeded

https://s3.amazonaws.com/archive.travis-ci.org/jobs/187592465/log.txt

Further investigation reveals:

  • error does not occur when running the individual mathtext tests, e.g. with python tests.py matplotlib.tests.test_mathtext, but only when running these tests as part of a full test suite python tests.py;
  • when dropping into the debugger on the test failure - python tests.py --pdb - this sequence of commands also cause the recursion error:
from matplotlib.font_manager import FontProperties
from matplotlib import mathtext as mt

my_p = mt.Parser()
backend = mt.MathtextBackendPath()
font_output = mt.BakomaFonts(FontProperties(), backend)
my_str = '$\\sqrt{1+\\sqrt{1+\\sqrt{1+\\sqrt{1+\\sqrt{1+\\sqrt{1+\\sqrt{1+x}}}}}}}$'
my_p._state_stack = [my_p.State(font_output, 'default', 'rm', 100, 72)]
my_p._em_width_cache = {}
result = my_p._expression.parseString(my_str)
print(result)

The same sequence of commands run on its own in Python 3.6, passes.

This string also generates the recursion errors, when dropped into the debugger:

r'$\cos{1 + \sqrt{1 + \sqrt{1 + \sqrt{1 + \sqrt{1 + \sqrt{1+\cos{1+x}}}}}}}$'

but not:

r'$\cos{1 + \sqrt{1 + \sqrt{1 + \sqrt{1 + \sqrt{1 + \cos{1+\cos{1+x}}}}}}}$'
r'$\cos{1 + \cos{1 + \cos{1 + \cos{1 + \cos{1 + \cos{1+\cos{1+x}}}}}}}$'
r'$\sqrt{1 + \sqrt{1 + \sqrt{1 + \sqrt{1 + \sqrt{1+\sqrt{1+x}}}}}}$'

It looks like there is some horrible global state in the MathText module or pyparsing that is being triggered only under certain circumstances.

@mdboom - can you reproduce? Any insights into the problem?

Activity

  1. added this to the milestone on Jan 11, 2017
  2. matthew-brett commented on Jan 14, 2017

    @matthew-brett
    ContributorAuthor

    @mdboom - do you have any time to look into this one? Or any suggestions as to how to investigate further?

  3. tacaswell commented on Jan 15, 2017

    @tacaswell
    Member

    Can the recursion limit on travis be pushed up? The test runner adds a whole bunch of layers, I wonder if we were always sitting on the limit?

  4. matthew-brett commented on Jan 15, 2017

    @matthew-brett
    ContributorAuthor

    Had a shot at that - but now tests all failing - https://travis-ci.org/MacPython/matplotlib-wheels/jobs/192055053#L1757 - something to do with the results images change?

  5. jkseppan commented on Jan 15, 2017

    @jkseppan
    Member

    That Travis log looks like it's installing matplotlib from a wheel, and as of recently the wheels don't include test images.

  6. matthew-brett commented on Jan 16, 2017

    @matthew-brett
    ContributorAuthor

    OK - I have solved the test images problem - see discussion over at #7757 (comment) .

    Upping the recursion limit does make the tests pass on Python 3.6 - see https://travis-ci.org/MacPython/matplotlib-wheels/jobs/192072933

    I've submitted a couple of PRs to add the ability to specify the recursion limit to the test function, see #7843, #7849.

    Once those are merged, I think wheel building will be OK for master and for the 2.x branch.

  7. tacaswell commented on Jan 17, 2017

    @tacaswell
    Member

    I can now reproduce this on linux as will, but only if I run the test suite not parallel.

  8. tacaswell commented on Jan 17, 2017

    @tacaswell
    Member

    Also, I wonder if that very deep recursion a performance bottle neck that we should be looking into.

  9. matthew-brett commented on Jan 17, 2017

    @matthew-brett
    ContributorAuthor

    It's certainly crazy slow to do the parsing - at one point I ran 1000 parses of that multiply nested sqrt string, and it took something like 30 seconds.

  10. dstansby commented on Feb 21, 2017

    @dstansby
    Member

    I've just run a plain pytest on python 3.6, OSX, and I'm not getting the above errors. Perhaps this was fixed by all the recent changes to testing?

  11. QuLogic commented on Feb 22, 2017

    @QuLogic
    Member

    Plain pytest does not run any of @matthew-brett's changes since those are part of matplotlib.test which isn't called that way. I don't recall much that would have had an effect here, though. And 3.6 on Travis/Linux never seemed to have the problem...

  12. tacaswell commented on Feb 22, 2017

    @tacaswell
    Member

    What does running plain pytest miss?

  13. QuLogic commented on Feb 22, 2017

    @QuLogic
    Member

    Anything custom in tests.py and matplotlib.test(), so the recursion limit increase and the warning filter thing. But the default recursion limit is to not change anything anyway, and I think we've already fixed everything that triggers the warnings.

  14. modified the milestones: , on May 3, 2017
  15. modified the milestones: , on Oct 9, 2017
  16. QuLogic commented on Nov 23, 2021

    @QuLogic
    Member

    We don't support Python 3.6, Matplotlib 2(ish), and the recursion limit stuff was removed, so I think there's nothing to do here.

  17. removed this from the future releases milestone on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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