reduce CPU usage

This commit is contained in:
blakeblackshear 2019-02-01 06:35:10 -06:00
parent 72393be6d6
commit 7e3d2f6611

View File

@ -193,6 +193,9 @@ def process_frames(shared_arr, shared_output_arr, shared_frame_time, frame_shape
if no_frames_available > 0 and (datetime.datetime.now().timestamp() - no_frames_available) > 30: if no_frames_available > 0 and (datetime.datetime.now().timestamp() - no_frames_available) > 30:
time.sleep(1) time.sleep(1)
print("sleeping because no frames have been available in a while") print("sleeping because no frames have been available in a while")
else:
# rest a little bit to avoid maxing out the CPU
time.sleep(0.01)
continue continue
# we got a valid frame, so reset the timer # we got a valid frame, so reset the timer
@ -202,6 +205,8 @@ def process_frames(shared_arr, shared_output_arr, shared_frame_time, frame_shape
if (datetime.datetime.now().timestamp() - shared_frame_time.value) > 0.5: if (datetime.datetime.now().timestamp() - shared_frame_time.value) > 0.5:
# signal that we need a new frame # signal that we need a new frame
shared_frame_time.value = 0.0 shared_frame_time.value = 0.0
# rest a little bit to avoid maxing out the CPU
time.sleep(0.01)
continue continue
# make a copy of the frame # make a copy of the frame