Client, Servers, subprocess.Popen, and .p3d

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
libpandaexpress.so
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.

David

fork is only on Mac & Unix. If you want Windows, you can get:

GetModuleFileName Function

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.

Actually I have a related question. The manual says:

This looks like a typo and it was meant to be, ‘omit the “packp3d”’.

The next page says,

This is very confusing, because I don’t have a binary called panda3d. Running packp3d gets me:

Is the runtime just the browser plug-in or something, and not the main distro/install?

Ok thanks and here’s your thread back.

You’re right, this is a result of incomplete edits. Corrected.

In the meantime, you have to install the Panda3D runtime (this is a separate download) in order to use packp3d.

David

When you launch the p3d a second time, you can check its argument flags (CL arguments) and take a separate branch. For example:

if len( sys.argv )== 1:
  import server
else:
  import client

There are some variations if this doesn’t work as-is but they start to get a little technical.

I am assuming you’re able to launch the p3d a second time, which I can’t attest to.