0

I am trying to use mmap to share data between two python scripts. I want to clear the buffer after each write. How to it?

for example:

import mmap
from time import sleep

while true:
a=mmap.mmap(0, 200, 'GlobalSharedMemory')
inp = bytes("Hello!","utf-8")
a.write(inp)
sleep(0.01)
#a[0:200] = []
# or:
#a.clear()
inp = bytes("How are you?,"utf-8")
a.write(inp)

Is there a clear method or something that can let me write again to the byte array from the beginning? I mean All rewrites should start from index 0. Thanks.

mj1261829
  • 1,200
  • 3
  • 26
  • 53

1 Answers1

0

Well, this what I have reached and will be using for now:

I set the byte array to 0 after waiting 10ms for the data to be read by the other python script:

sleep(0.01)
a[0:200] = b"\x00"*200

at the other end I remove all 0 (empty) bytes so I get the correct result. However, if anyone else found a better way please post it.

mj1261829
  • 1,200
  • 3
  • 26
  • 53