Last active
March 9, 2021 18:59
-
-
Save bml1g12/54b448772a077d15be5ab9a710f28cf0 to your computer and use it in GitHub Desktop.
Shared memory for communicating Numpy arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consumer_shared_memory(n_frames, shared_memory): | |
"""A frame consumer function, which draws frames from the worker process via shared memory.""" | |
mp_array, np_array = shared_memory | |
for _ in range(n_frames): | |
_ = np_array.astype("uint8").copy() * 2 # example of some processing done on the array | |
while True: | |
try: | |
mp_array.release() | |
break | |
# it already unlocked, wait until its locked again which means a new frame is ready | |
except ValueError: | |
time.sleep(0.001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment