Question

Sorry if this question is incredibly easy to answer, or I sound like an idiot. I'm wondering how I would execute a script in one file, pygame event loop, blits, etc, then switch to another file, SelectWorld.py, which has it's own event loop, and blits, and etc. If I just call it's main function, does it create any slowdown because I still have the original file open, or am I fine just doing that? SelectWorld.transition() sort of thing. Thanks in advance.

Was it helpful?

Solution 3

Turns out the answer to this was painfully simple, and I asked this back when I was just learning Python. There is no speed downgrade from just calling a function from another file and letting it do all the work. Thanks for all the answers, guys.

OTHER TIPS

Here's a suggestion: create two version of your script. Dump everything into one. In the other, do the proper thing of laying out your code into separate files with smart filenames.

Now, run the first with this command:

 $ time python my_game_all_in_one.py

(The dollar sign represents the command line prompt.) And run the second:

 $ time python my_game.py

The time command will tell you how much time the game actually took to run, both in real time, and how much CPU time it took. Run both commands, say, ten times each, and take the average of each time.

This is called "profiling," and it will help you decide which approach is best, or if it even makes a difference.

Here, what is wanted is to be able to share the variables between two different applications: 2 different scripts with event loops, blits, etc. So by definition, they should be on different process (if they must be running at the same time).

There is two major ways of doing this:

1 - Client-Server Architecture (like a Game server would be) (the server and client can both run on the same machine)

2 - Multiprocessing with 2 process running on the same machine with different ways of communicating and synchronize the variables. (Pipe Queue, Event, etc)

I understand that you're trying to do a kind of variables profiling of your game? If it is used to debug your game or test it. I consider that you need a lot of code to gain a little useful information (because the game might run too fast for you to analyse the variables)

You have those alternatives:

1 - import pdb, pdb.set_trace(): it will stop the process at the line where you called the function and, on the terminal, you can see the variables values.

2 - You can use Eclipse (with pyDev): Very good debugger (line by line)

3 - Unittest, Mock: Is something you should start to use, because it is useful, because you can easily see when you break some old code (with unittest) and/or testing new code...

I hope it helps you :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top