Skip to content

Commit

Permalink
✨ Wait server
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Jan 22, 2025
1 parent 9a01333 commit f4db0b6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/craftground/environment/boost_ipc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from ..environment.ipc_interface import IPCInterface
from ..proto.action_space_pb2 import ActionSpaceMessageV2
from ..proto.initial_environment_pb2 import InitialEnvironmentMessage
Expand All @@ -13,6 +14,7 @@
write_to_shared_memory, # noqa
read_from_shared_memory, # noqa
destroy_shared_memory, # noqa
shared_memory_exists, # noqa
)


Expand Down Expand Up @@ -63,9 +65,23 @@ def remove_orphan_java_processes(self):

def start_communication(self):
# wait until the j2p shared memory is created
wait_time = 1
next_output = 1 # 3 7 15 31 63 127 255 seconds passed
while True:
if self.is_alive():
if shared_memory_exists(self.j2p_shared_memory_name):
break
self.logger.log(
f"Waiting for Java process to create shared memory {self.j2p_shared_memory_name}"
)
time.sleep(wait_time)
wait_time *= 2
if wait_time > 1024:
raise Exception(
f"Java process failed to create shared memory {self.j2p_shared_memory_name}"
)
self.logger.log(
f"Java process created shared memory {self.j2p_shared_memory_name}"
)

def __del__(self):
self.destroy()

0 comments on commit f4db0b6

Please sign in to comment.