-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pickling error in Numba exception handling & improve cache checks (…
…#1083) * attempt to fix recursion error (1) * better checks for caching * add better check if a numba function is cached or needs to be re-compiled * add case for non-numba functions
- Loading branch information
Showing
4 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import pickle | ||
import numba | ||
|
||
|
||
def is_numba_function_cached(func): | ||
""" | ||
Determines if a numba function is cached and up-to-date. | ||
Returns: | ||
- True if cache exists and is valid or the input is not a Numba function. | ||
- False if cache doesn't exist or needs recompilation | ||
""" | ||
|
||
if not hasattr(func, "_cache"): | ||
return True | ||
|
||
cache = func._cache | ||
cache_file = cache._cache_file | ||
|
||
# Check if cache file exists | ||
full_path = os.path.join(cache._cache_path, cache_file._index_name) | ||
if not os.path.isfile(full_path): | ||
return False | ||
|
||
try: | ||
# Load and check version | ||
with open(full_path, "rb") as f: | ||
version = pickle.load(f) | ||
if version != numba.__version__: | ||
return False | ||
|
||
# Load and check source stamp | ||
data = f.read() | ||
stamp, _ = pickle.loads(data) | ||
|
||
# Get current source stamp | ||
current_stamp = cache._impl.locator.get_source_stamp() | ||
|
||
# Compare stamps | ||
return stamp == current_stamp | ||
|
||
except (OSError, pickle.PickleError): | ||
return False |