The problem here is that each of the processes end up with a different port due to get_open_port. As a result, the processes can’t rendezvous properly. The MASTER_PORT env variable needs to be the same on all processes and you probably need to choose a fixed port for this. The other option is to find a free port on the master, then communicate this port to all processes using some out of band mechanism to ensure all processes use the same port.
For example, if you’re running all processes on a single host (which is what your example code does). You can call get_open_port in the run_demo function and pass the free port to all processes as an argument to the demo_func method.