For my game I use a client/server model even in a single player setting. What I’ve done is spawn server.py using subprocess.Popen([sys.executable, ‘Server.py’, ‘SP’]). Trying to launch it with this method spits out
Error reading Can't find 4096 bytes
Successfully joined thread: 0
Failure on startup.
Both client and server are seperate panda apps with their own run loops.
I assume this is not a good way to go about this. Do I need to make two seperate p3d, one for the client and one for the server? Is there a way to launch the server in the same p3d?
sys.executable is certainly not going to be a runnable standalone Python executable, because we don’t ship a standalone Python executable in the runtime. Instead, the Python interpreter is embedded in a more special-purpose executable.
So, yeah, not really a good way to go about it. I’m not familiar with the subprocess module, but is there a way to spawn a subprocess using something like fork(), without having to restart the interpreter from the main entry point? Perhaps separate p3d files would be simpler.
fork is only on Mac & Unix. If you want Windows, you can get:
Retrieves the fully-qualified path for the file that contains the specified module
If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process.
Which may or may not completely cover your use case; that is, may have reliability holes.
You can call it through ctypes.windll or ctypes.windll.kernel32 (iirc), and build a second process’s command line.
If that won’t be any use due to the details of this p3d, you could just use a 2nd thread and try to keep it especially isolated, possibly even using tricks for that part.