[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Preventing multiple instances of your game from running (and activating the running copy?)




On Aug 4, 2006, at 6:26 PM, Brian Fisher wrote:

Hey all,
 I want to write some code to make my pygame apps prevent multiple
instances from running, and if possible (although I doubt it is...)
make the currently running copy of the game activated if another
instance gets run.

Also, I want to use some method that works great cross-platform, and I
don't want to use any method that could break with a crashed app (like
marker files or whatever... I mention this cause the 2 samples I found
in google were using mutex's with win32 extensions and using a marker
file)

So do you guys have a feature like that in your games? What approach
do you guys take?

I've don't recall ever seeing a game on unix that really cared if it was running already or not. Seems like YAGNI.


I can see it making some sense on win32, but is it actually a problem worth solving?

On Mac OS X, if using an application bundle anyway, this is the default behavior. You have to specifically ask for an application that can be run multiple times simultaneously for the same user.

If I really had to do something like this, I'd do it with TCP on 127.0.0.1 plus a marker file in a user-specific directory that said which port to look for (which is determined at runtime by asking for port 0). Connecting to that port would spit out some expected handshake (e.g. the name of the game and then disconnect). This would let you know that the game is still running on the same machine by the same user.

-bob