summaryrefslogtreecommitdiff
path: root/nemesis/nemesis.py
diff options
context:
space:
mode:
Diffstat (limited to 'nemesis/nemesis.py')
-rwxr-xr-xnemesis/nemesis.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/nemesis/nemesis.py b/nemesis/nemesis.py
index 812cd2d..0c34121 100755
--- a/nemesis/nemesis.py
+++ b/nemesis/nemesis.py
@@ -150,7 +150,7 @@ class Nemesis(object):
loops = Nemesis.experiment_data.get_loops()
exp_coro = Nemesis.experiment_coro
for loop in loops:
- coro = Nemesis._get_current_frame(loop).f_code.co_name
+ coro = Nemesis._frame_to_name(Nemesis._get_current_frame(loop))
prev_coro = Nemesis.prev_coro[loop]
if not prev_coro == coro:
if prev_coro == exp_coro:
@@ -171,10 +171,10 @@ class Nemesis(object):
for loop in loops:
frame = Nemesis._get_current_frame(loop)
if frame is not None and Nemesis._is_child_of_async(frame):
- frames.append(frame.f_code.co_name)
+ frames.append(Nemesis._frame_to_name(frame))
if frames:
- Nemesis._start_experiment(random.choice(frames),
- Nemesis._select_speedup())
+ next_frame = random.choice(frames)
+ Nemesis._start_experiment(next_frame, Nemesis._select_speedup())
@staticmethod
def _parse_handle(handle):
@@ -256,13 +256,18 @@ class Nemesis(object):
if 'nemesis' in fname:
return False
+ # written this way to avoid hitting max recusion depth
f = Path(fname).resolve()
- i = any(f.is_relative_to(p) for p in Nemesis.path_include)
- if not i:
+ f_par = set(f.parents)
+ f_par.add(f)
+
+ if not any(p in f_par for p in Nemesis.path_include):
+ return False
+
+ if any(p in f_par for p in Nemesis.path_exclude):
return False
- e = any(f.is_relative_to(p) for p in Nemesis.path_exclude)
- return not e
+ return True
def _select_speedup() -> float:
'''
@@ -275,9 +280,9 @@ class Nemesis(object):
@staticmethod
def _get_coro_name(coro):
- '''
+ """
Stolen from _format_coroutine in cpython/Lib/asyncio/coroutines.py
- '''
+ """
# Coroutines compiled with Cython sometimes don't have
# proper __qualname__ or __name__. While that is a bug
# in Cython, asyncio shouldn't crash with an AttributeError
@@ -290,3 +295,11 @@ class Nemesis(object):
# Stop masking Cython bugs, expose them in a friendly way.
coro_name = f'<{type(coro).__name__} without __name__>'
return f'{coro_name}()'
+
+ @staticmethod
+ def _frame_to_name(frame):
+ """
+ """
+ fname = frame.f_code.co_filename
+ func = frame.f_code.co_name
+ return f"{fname}:{func}"