Suppose, just for a moment, that you've been asked to write a big Python book and you want to provide a way for readers to easily start the book's examples on just about any platform that Python runs on. Books are nice, but it's awfully fun to be able to click on demos right away. That is, you want to write a general and portable launcher program in Python for starting other Python programs. What to do?
In this chapter, we've seen how to portably spawn threads, but
these are simply parallel functions, not external programs. We've also
learned how to go about starting new, independently running programs,
with both the
exec combination and with tools for
launching shell commands such as
os.system. Along the way, though, I've also
been careful to point out numerous times that the
os.fork call doesn't work on Windows today.
This constraint may be improved by the time you read this book, but it
still is a limitation as I write these words. Moreover, for reasons
we'll explore later, the
call is prone to blocking (pausing) its caller in some scenarios and
requires a potentially platform-specific command-line string.
Luckily, there are other ways to start programs in the Python standard library, some of which are more platform neutral than others:
os.spawnve calls were
originally introduced to launch programs on Windows, much like a
exec call combination on Unix-like platforms. Today, these calls work on both Windows ...