Reputation: 108
i have two python unrelated subprocces, and my wait method was something like the following
def wait(self):
LIMIT = 3
t0 = time.time()
while 1:
message = self.__read_message()
if message != '\x00':
break
if time.time() - t0 > LIMIT:
time.sleep(0.01)
return message
the read message method is reading a message from a mmap shared memory then delete the message
def __read_message(self):
with self.__sem2:
msg = self.mem[self.__PTR_READ:self.__PTR_READ + self.__MSG_LEN]
self.mem[self.__PTR_READ:self.__PTR_READ + self.__MSG_LEN] = b"\x00" * self.__MSG_LEN
self.mem.flush()
return self.__message.unpack(msg)
can i improve it so that there is no busy waiting? i have used the subprocess module to create my other python process if this can help
Upvotes: 0
Views: 197