Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed acquisition function to release the TimeoutLock when not actively querying data #614

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions socs/agents/hwp_pid/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,15 @@ def acq(self, session, params):
'last_updated': 1649085992.719602}

"""
with self.lock.acquire_timeout(timeout=10, job='acq') as acquired:
if not acquired:
self.log.warn('Could not start iv acq because {} is already running'
.format(self.lock.job))
return False, 'Could not acquire lock'

session.set_status('running')
last_release = time.time()
self.take_data = True

while self.take_data:
# Relinquish sampling lock occasionally.
if time.time() - last_release > 1.:
last_release = time.time()
if not self.lock.release_and_acquire(timeout=10):
self.log.warn(f"Failed to re-acquire sampling lock, "
f"currently held by {self.lock.job}.")
continue
session.set_status('running')
self.take_data = True

while self.take_data:
with self.lock.acquire_timeout(timeout=10, job='acq') as acquired:
if not acquired:
self.log.warn('Could not take iv acq because {} is already running'
.format(self.lock.job))
continue

data = {'timestamp': time.time(),
'block_name': 'HWPPID', 'data': {}}
Expand All @@ -314,7 +305,7 @@ def acq(self, session, params):
'direction': direction,
'last_updated': time.time()}

time.sleep(5)
time.sleep(5)

self.agent.feeds['hwppid'].flush_buffer()
return True, 'Acqusition exited cleanly'
Expand Down