for Windows or Unix; use P_NOWAIT for dos box;
forward slashes are okay here
"""
def run(self, cmdline):
os.spawnv(os.P_DETACH, pypath, (pyfile, cmdline))
class Top_level(LaunchMode):
"""
run in new window, same process
tbd: requires GUI class info too
"""
def run(self, cmdline):
assert False, 'Sorry - mode not yet implemented'
pick a "best" launcher for this platform
may need to specialize the choice elsewhere
if sys.platform[:3] == 'win':
PortableLauncher = Spawn
else:
PortableLauncher = Fork
class QuietPortableLauncher(PortableLauncher):
def announce(self, text):
pass
def selftest():
file = 'echo.py'
input('default mode...')
launcher = PortableLauncher(file, file)
launcher() # no block
input('system mode...')
System(file, file)() # blocks
if sys.platform[:3] == 'win':
input('DOS start mode...') # no block
StartArgs(file, file)()
if name == 'main': selftest()
Near the end of the file, the module picks a default class based on the sys.platform
attribute: PortableLauncher is set to a class that uses spawnv on Windows and one that
uses the fork/exec combination elsewhere; in recent Pythons, we could probably just
use the spawnv scheme on most platforms, but the alternatives in this module are used
in additional contexts. If you import this module and always use its Portable
Launcher attribute, you can forget many of the platform-specific details enumerated in
this chapter.
To run a Python program, simply import the PortableLauncher class, make an instance
by passing a label and command line (without a leading “python” word), and then call
266 | Chapter 5: Parallel System Tools