Skip to content

Commit 73f87e8

Browse files
committed
use a try/except instead
1 parent 3013dbe commit 73f87e8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/pytest_run_parallel/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def visit_Assign(self, node):
117117
self.generic_visit(node)
118118

119119

120-
@functools.lru_cache
121-
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
120+
def _identify_thread_unsafe_nodes(fn, skip_set, level=0):
122121
if is_hypothesis_test(fn):
123122
return True, "uses hypothesis"
124123
try:
@@ -131,6 +130,17 @@ def identify_thread_unsafe_nodes(fn, skip_set, level=0):
131130
return visitor.thread_unsafe, visitor.thread_unsafe_reason
132131

133132

133+
cached_thread_unsafe_identify = functools.lru_cache(_identify_thread_unsafe_nodes)
134+
135+
136+
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
137+
try:
138+
return cached_thread_unsafe_identify(fn, skip_set, level=level)
139+
except TypeError:
140+
# skip caching if we hit an error about fn not being hashable
141+
return _identify_thread_unsafe_nodes(fn, skip_set, level=level)
142+
143+
134144
class ThreadComparator:
135145
def __init__(self, n_threads):
136146
self._barrier = threading.Barrier(n_threads)

0 commit comments

Comments
 (0)