Skip to content

Commit

Permalink
hooks: tensorflow: automatically raise recursion limit
Browse files Browse the repository at this point in the history
Several tests on the CI are throwing recursion error with
`tensorflow` 2.18.0 installed, so have `tensorflow` hook automatically
raise the recursion limit to 5000 (unless it is already at higher
value).

The problem does not seem to be tied to this `tensorflow` version
(building in a clean environment with just `tensorflow` and its
dependencies installed seems to pass without errors), but rather
to specific import chains that involve `tensorflow` but also depend
on the build environment (i.e., other packages installed in it).
  • Loading branch information
rokm committed Oct 29, 2024
1 parent 5818893 commit f6922d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions _pyinstaller_hooks_contrib/stdhooks/hook-tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

import sys

from _pyinstaller_hooks_contrib.compat import importlib_metadata
from packaging.version import Version

Expand All @@ -23,6 +25,14 @@
logger,
)

# Automatically raise recursion limit to ensure it is at least 5000; this attempts to mitigate recursion limit errors
# caused by some import chains that involve tensorflow, but also depend on the build environment (i.e., other packages
# installed in it).
new_limit = 5000
if sys.getrecursionlimit() < new_limit:
logger.info("hook-tensorflow: raising recursion limit to %d", new_limit)
sys.setrecursionlimit(new_limit)

# Determine the name of `tensorflow` dist; this is available under different names (releases vs. nightly, plus build
# variants). We need to determine the dist that we are dealing with, so we can query its version and metadata.
_CANDIDATE_DIST_NAMES = (
Expand Down
4 changes: 4 additions & 0 deletions news/825.update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Update ``tensorflow`` hook to automatically raise recursion limit to
5000 (if not already set to a higher value) in order to avoid recursion
limit errors in certain import chains (dependent on build environment
and other packages installed in it).

0 comments on commit f6922d0

Please sign in to comment.