[Tutor] running more than one python program at the same time
William R. Wing (Bill Wing)
wrw at mac.com
Wed Aug 29 14:27:28 CEST 2012
On Aug 28, 2012, at 11:28 PM, akleider at sonic.net wrote:
>> On 08/28/2012 03:30 PM, 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. Do you know if there's
>>> a way to do this? Or do I need to buy a second computer?
>>> Thanks,
>>> Ben
>> Can you make each script executable and run them without idle?
>>
>>
>> Ray
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
> The following works with Linux and might with OSX as well.
I sent the paragraphs below to Ben yesterday as an off-list message because I figured it wasn't of general enough interest. But, in the hope of sharing knowledge, I'm resending, this time to the list.
----
Ben, On Mac OS-X you have several options. Apple's python (and the python.org copy) both install a minimalist app called PythonLauncher. Assuming it is present (look in your Applications folder, possibly in a Python folder there), simply double-clicking on a <myscript>.py file in the Finder will launch that script.
In general, Mac editors that are python-aware will save python scripts as executable (look for rwx in the owner column of an "ls -l" terminal listing). If the script isn't executable, type chmod +x <yourscriptname>.py<return> in the terminal window (<return> is the Return key).
Assuming the script is executable, in a terminal window, you can type "python <yourscriptname>.py and the python interpreter will be told to run the .py file.
Next, if the first line in the python file is #!/usr/bin/env python (or if it explicitly references the version of python you are using) then in the terminal, you can type ./<yourscriptname>.py and the bash shell will invoke python for you.
If it is a script that needs to be running all the time, you can turn it into a stand-alone application using py2app or PythonInstaller and place the resulting applications in your list of login items. Google will get you to either of both of those.
Finally, if it needs to be run in response to some particular event (like mounting a disk) or at a particular time of day, you can create a launchd plist file and use launchctl to create an entry in the launchd daemon list. (This is a very much more complex subject than this one-liner might imply, and needs to be taken up on a different list.)
-Bill
More information about the Tutor
mailing list