Closed devinsaini closed 3 years ago
Hi @devinsaini does this also hang if you run side_process()
from a separate script (i.e. without using multiprocessing)?
@fastturtle Yes it hangs even if I run it from a separate script. However, I was able to get the following script to work, where I start both server and client in separate processes.
import reverb
import multiprocessing
def main():
server_proc = multiprocessing.Process(target=server_process)
server_proc.start()
client_proc = multiprocessing.Process(target=client_process)
client_proc.start()
client_proc.join()
def server_process():
server = reverb.Server(tables=[
reverb.Table(
name='cartpole',
sampler=reverb.selectors.Uniform(),
remover=reverb.selectors.Fifo(),
max_size=100,
rate_limiter=reverb.rate_limiters.MinSize(1))
],
port=8000
)
server.wait()
def client_process():
client = reverb.Client('localhost:8000')
print(f"Client process : {client.server_info()}")
print("Client process terminated")
if __name__ == '__main__':
main()
One more thing, since I haven't implemented a clean way to call server.stop()
, I manually kill the process using port 8000 using kill -9 $(sudo lsof -t -i:8000)
before running it again. Here's an output of lsof after running the program and quitting ^Z out of it:
~$ sudo lsof -i:8000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python3 17058 devin 5u IPv6 467873 0t0 TCP *:8000 (LISTEN)
python3 17096 devin 5u IPv6 467873 0t0 TCP *:8000 (LISTEN)
However, the first script I posted doesn't work even when there's nothing using port 8000.
@devinsaini Set the subprocess start method to 'spawn' will fix this issue.
import reverb
import multiprocessing
def side_process():
print("Side process started")
client = reverb.Client('localhost:8000')
print(f"Side process : {client.server_info()}")
print("Side process terminated")
def main():
server = reverb.Server(tables=[
reverb.Table(
name='cartpole',
sampler=reverb.selectors.Uniform(),
remover=reverb.selectors.Fifo(),
max_size=100,
rate_limiter=reverb.rate_limiters.MinSize(1))
],
port=8000
)
client = reverb.Client('localhost:8000')
print(f"Main process : {client.server_info()}")
side_proc = multiprocessing.Process(target=side_process)
side_proc.start()
server.wait()
if __name__ == '__main__':
multiprocessing.set_start_method('spawn')
main()
@zhangxiaochuan thanks for your answer! I'm closing this issue as using the spawn strategy (instead of fork, which is default on Linux OSes) fixes this issue.
I'm trying to run reverb client and server in separate processes using multiprocessing. I've tried both dm-reverb 0.2.0 and dm-reverb-nightly 0.3.0.dev20210402 on Python 3.8, but getting the same result with the following piece of code. One key info is that I'm running this on Windows machine with WSL2 on Ubuntu 20.04.
The main process client works fine, but side process client hangs at the call to client.server_info(). I've also tried client.sample() after writing some data from main process and trying to access in the side process with the same result.