[Tutor] running more than one python program at the same time

Steven D'Aprano steve at pearwood.info
Wed Aug 29 04:35:16 CEST 2012


On 29/08/12 08:30, Benjamin Fishbein wrote:
> Hello,
> I wrote a program that I want to have running 24/7. But the problem is
> that I also want to write and run other programs. I'm using Idle and
>it won't let me run more than one script at a time.

Then don't use IDLE. IDLE is for running code interactively, not for
long-running programs


>  Do you know if there's a way to do this? Or do I need to buy a second
> computer?

Your computer is already running dozens, possible hundreds of programs
simultaneously. On my home box, I can see 198 programs currently active.
They don't call them "multitasking operating systems" for nothing :)

(Actually, "multitasking" is one of those things that people no longer
talk about, because it's just assumed that *every* computer does it. This
was not always the case -- twenty years ago, the difference between single
and multitasking computers was a big deal. Now, probably the only computer
you have that doesn't multitask is your microwave oven. Even your iPhone
multitasks -- it just won't let apps multitask, but the phone itself does.)

You need to run your python script the same way you run any other script
for your system:

In Windows, you will need something like a batch file or equivalent, which
directly runs your script using the Python interpreter. Put this batch
file wherever you put other batch files that you want to be run
automatically when the system starts up.

In Linux, you can set your script as an init.d script to have it
automatically run by the operating system. If you're using a GUI desktop
like KDE, Trinity, Gnome or similar, it will have something equivalent to
a "startup folder" where you put files you want to run when the desktop
starts.

If you're running a Mac, there will be something similar.

If you can't be bothered, or don't want, your system to automatically
start up your script, you can run it manually from your system's shell.
In Windows, that is the DOS prompt -- either cmd.com or command.exe, I
never remember which one is which. In Linux, you start up an xterm or
other terminal window. Using KDE, I can do either of these:

Start menu > System > Terminal

or right-click on the desktop and select "Konsole".

Because I use a terminal so often, I have a shortcut permanently in my
task bar so I can open a terminal with one click. Other desktops will
have something similar.

However you do it, you will get a terminal/xterm/console/DOS prompt
window, showing a dollar sign prompt:

$

That's the shell, waiting for you to give it commands. You can now run
your python script. At the prompt, type:

python /path/to/my/script.py

then press ENTER.

If your script needs arguments passed from the command line, put them
after the path:

python /path/to/my/script.py -z --foo --bar spam ham eggs 23 42

but I'm guessing that if you don't know how to run a script from the
command line, it probably doesn't need command line arguments :)




-- 
Steven


More information about the Tutor mailing list