Stopping the interactive loop (newbie question)

Is there a way in my scripts to return to the python prompt so I can poke at my program a bit?
(that is, once I’ve called run(), is there a “stop” or something like that)

Ideally I could put “stop” into a key handler, or have it triggered as an event or …
I guess there might be a matching “continue” since I probably wouldn’t want to call run again.

Thanks,

mg

It’s designed so that the keyboard interrupt (i.e. control-C) will break into the program and return you to the prompt, until you type run() again.

David

Does that mean that things like a ‘pause’ function can not be called on the engine in python?

Roel

edit: made the question less ambigues

No, you could do that. It depends on what you mean be a pause() function. You could always write a function that does absolutely nothing, waiting for some event to occur, and that will effectively block the entire application. Or, if you want to return the user to a prompt, you could simply raise the Python exception of your choice. If you raise KeyboardInterrupt, it will be the cleanest break, since the Task manager will trap this and defer it until after the task loop has fully completed one pass. But if you don’t care about that detail (and most people probably won’t), any exception would be fine.

David

I think what he’s interested in is the function ‘taskMgr.stop()’

The code for “run” is inside direct/src/task/Task.py. It says this:

class TaskManager:
    ...
    def run(self):
        ...
        self.running = 1
        while self.running:
             ...

    def stop(self):
        # Set a flag so we will stop before beginning next frame
        self.running = 0

David and Josh - thanks

taskMgr.stop is exactly what I wanted (well, almost - it has the wierd effect that if I didn’t start with an interactive prompt it exits entirely, so i just need to run my program using “import” rather than from the shell command line)

ctrl-c would be handy, but it doesn’t seem to work

mg

If you run ppython with the -i command line option it’ll put you in interactive mode.

ppython -i Main.py

That way when you call taskMgr.stop it’ll put you in the interactive prompt instead of exiting completely.