我正在使用下面的三个函数(queue_value_emptier
,step_emptier
和step_through
)来计算一组点之间的差,并在这两个点之间做一些较小的步骤。
还有其他两个与step_through
功能共享锁的过程(摄像机序列和数据保存)。这是因为当值逐渐增加时,我不希望保存摄像机/数据,反之亦然。
def queue_value_emptier(self, queued_dict):
"""Recursively empty the queue values of the dict"""
if self.paused is True:
self.queue_value_emptier(queued_dict)
updated_dict = {}
for key, value in queued_dict.items():
new_val = value.get()
updated_dict[key] = new_val
self.update(updated_dict)
time.sleep(self.transition_time)
# Base case
if value.empty():
return
# Check paused
elif self.paused:
return
else:
# Recursion call
self.queue_value_emptier(queued_dict)
def step_emptier(self, step_list, nested_dict):
"""Iterating through each step"""
for step in step_list:
step_dict = nested_dict[step]
self.queue_value_emptier(step_dict)
return
def step_through(self, seg):
"""Select which segment to run"""
if seg is None:
# Here to start the process without actually starting anything
return
# When the segment is available
self.seg_selected = OrderedDict(self.segments[seg])
self.lock.acquire()
# Creating a nested dict with queue values
step_order = []
step_order, dynamic_dict = self.step.stepping_through(self.seg_selected, self.tcp.dynamic, self.step_size)
self.step_emptier(step_order, dynamic_dict)
self.lock.release()
该代码完全按照我的需要工作。问题在于,我希望能够使用以下功能在终端中暂停,恢复和停止渐变值:
def pause(self):
"""Freezes the state at it's current properties"""
self.paused = True
def resume(self):
"""Unfreezes the state and continues running the queue"""
self.paused = False
def stop(self):
"""Stop daemons"""
self.step_through('Stop') # Calls the stop sequence
# Ramping values to zero
self.paused = False
# Stopping threads
self.fpga.stop()
self.tcp.stop()
self.process.stop()
我发现无法访问这些功能,因为该锁阻止了其他所有操作。我只是一辈子都无法弄清楚他们是如何工作的,因为必须使用锁。