def run_producer(name, size, delay): buffer = RingBuffer(name=name, size=size, create=True) shutdown = False def terminate(signum, frame): nonlocal shutdown print( "Received=", signal.Signals(signum).name, "Attempting graceful shutdown of producer", ) shutdown = True signal.signal(signal.SIGTERM, terminate) signal.signal(signal.SIGINT, terminate) try: while not shutdown: buffer.put(get_next_message()) print(f"Reader: {buffer.reader_pos()} Writer: {buffer.writer_pos()}") time.sleep(delay) buffer.destroy() print(f"Destroyed shared memory buffer {name}") except Exception as ex: buffer.destroy() print(f"Error {str(ex)}. Destroying shared memory buffer and exiting") traceback.print_exc(file=sys.stdout) sys.exit(1)
def create_buffer(): buff = RingBuffer(name="test", size=100, create=True) yield buff buff.destroy()