Skip to content
Snippets Groups Projects
Verified Commit 38d6a968 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Fix automatic delay detection

parent 5a3d0240
No related branches found
No related tags found
1 merge request!66Extend simulator module
Pipeline #1639842 waiting for manual action
...@@ -59,12 +59,12 @@ def with_delay(meth): ...@@ -59,12 +59,12 @@ def with_delay(meth):
@wraps(meth) @wraps(meth)
def wrapped(self, *, delay=True, **settings): def wrapped(self, *, delay=True, **settings):
skip_wait = getattr(wrapped, '__with_delay', False) skip_delay = settings.pop('_skip_delay', False)
if delay is True: if delay is True:
delay = settings['n_pts'] / settings['fs'] delay = settings['n_pts'] / settings['fs']
it = meth(self, **settings) it = meth(self, _skip_delay=True, **settings)
while True: while True:
tic = time.perf_counter() tic = time.perf_counter()
try: try:
...@@ -72,8 +72,8 @@ def with_delay(meth): ...@@ -72,8 +72,8 @@ def with_delay(meth):
except StopIteration as stop: except StopIteration as stop:
return stop.value return stop.value
else: else:
if delay and not skip_wait: if delay and not skip_delay:
time.sleep(delay - (time.perf_counter() - tic)) time.sleep(max(0, delay - (time.perf_counter() - tic)))
yield data yield data
...@@ -91,7 +91,6 @@ def with_delay(meth): ...@@ -91,7 +91,6 @@ def with_delay(meth):
parameters = parameters + [delay_param] parameters = parameters + [delay_param]
wrapped.__signature__ = wrapped_sig.replace(parameters=parameters) wrapped.__signature__ = wrapped_sig.replace(parameters=parameters)
wrapped.__with_delay = True
return wrapped return wrapped
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment