[Python-checkins] python/nondist/peps pep-0324.txt, 1.1,
1.2 pep-0000.txt, 1.275, 1.276
goodger at users.sourceforge.net
goodger at users.sourceforge.net
Tue Aug 3 15:13:59 CEST 2004
Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16990
Modified Files:
pep-0324.txt pep-0000.txt
Log Message:
update from Peter Astrand
Index: pep-0324.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0324.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pep-0324.txt 2 Jan 2004 20:53:01 -0000 1.1
--- pep-0324.txt 3 Aug 2004 13:13:43 -0000 1.2
***************
*** 1,4 ****
PEP: 324
! Title: popen5 - New POSIX process module
Version: $Revision$
Last-Modified: $Date$
--- 1,4 ----
PEP: 324
! Title: process - New POSIX process module
Version: $Revision$
Last-Modified: $Date$
***************
*** 34,38 ****
process creation. This makes it hard for developers to choose.
! The popen5 modules provides the following enhancements over
previous functions:
--- 34,38 ----
process creation. This makes it hard for developers to choose.
! The process module provides the following enhancements over
previous functions:
***************
*** 57,62 ****
current functions, without using temporary files.
! - With popen5, it's possible to control if all open file
! descriptors should be closed before the new program is
executed.
--- 57,62 ----
current functions, without using temporary files.
! - With the process module, it's possible to control if all open
! file descriptors should be closed before the new program is
executed.
***************
*** 79,83 ****
The following points summarizes the design:
! - popen5 was based on popen2, which is tried-and-tested.
- The factory functions in popen2 have been removed, because I
--- 79,83 ----
The following points summarizes the design:
! - process was based on popen2, which is tried-and-tested.
- The factory functions in popen2 have been removed, because I
***************
*** 85,99 ****
- popen2 contains several factory functions and classes for
! different combinations of redirection. popen5, however,
! contains one single class. Since popen5 supports 12 different
! combinations of redirection, providing a class or function for
! each of them would be cumbersome and not very intuitive. Even
! with popen2, this is a readability problem. For example, many
! people cannot tell the difference between popen2.popen2 and
! popen2.popen4 without using the documentation.
! - One small utility function is provided: popen5.run(). It aims
! to be an enhancement over os.system(), while still very easy to
! use:
- It does not use the Standard C function system(), which has
--- 85,99 ----
- popen2 contains several factory functions and classes for
! different combinations of redirection. process, however,
! contains one single class. Since the process module supports 12
! different combinations of redirection, providing a class or
! function for each of them would be cumbersome and not very
! intuitive. Even with popen2, this is a readability problem.
! For example, many people cannot tell the difference between
! popen2.popen2 and popen2.popen4 without using the documentation.
! - Two small utility functions are provided: process.call() and
! process.callv(). These aims to be an enhancement over
! os.system(), while still very easy to use:
- It does not use the Standard C function system(), which has
***************
*** 106,109 ****
--- 106,146 ----
- The return value is easier to work with.
+ The call() utility function accepts an 'args' argument, just
+ like the Popen class constructor. It waits for the command to
+ complete, then returns the returncode attribute. The
+ implementation is very simple:
+
+ def call(*args, **kwargs):
+ return Popen(*args, **kwargs).wait()
+
+ The motivation behind the call() function is simple: Starting a
+ process and wait for it to finish is a common task.
+
+ The callv() function is identical to call(), except that each
+ non-keyword argument is treated as a program argument. This
+ gives a slightly nicer syntax. The drawback is that callv() does
+ not allow specifying the program and it's arguments as a
+ whitespace-separated string: The entire (first) string would be
+ intepreted as the executable. The implementation of callv() is
+ also very simple:
+
+ def callv(*args, **kwargs):
+ return Popen(args, **kwargs).wait()
+
+ While Popen supports a wide range of options, many users have
+ simple needs. Many people are using os.system() today, mainly
+ because it provides a simple interface. Consider this example:
+
+ os.system("stty sane -F " + device)
+
+ With process.call(), this would look like:
+
+ process.call(["stty", "sane", "-F", device])
+
+ Some people feel that the list brackets are clumsy. With
+ callv(), they are not needed:
+
+ process.callv("stty", "sane", "-F", device)
+
- The "preexec" functionality makes it possible to run arbitrary
code between fork and exec. One might ask why there are special
***************
*** 120,127 ****
sense even on Windows.
- - No MS Windows support is available, currently. To be able to
- provide more functionality than what is already available from
- the popen2 module, help from C modules is required.
-
Specification
--- 157,160 ----
***************
*** 129,144 ****
This module defines one class called Popen:
! class Popen(args, bufsize=0, argv0=None,
stdin=None, stdout=None, stderr=None,
! preexec_fn=None, preexec_args=(), close_fds=0,
! cwd=None, env=None, universal_newlines=0)
!
! Arguments are:
!
- args should be a sequence of program arguments. The program to
execute is normally the first item in the args sequence, but can
! be explicitly set by using the argv0 argument. The Popen class
! uses os.execvp() to execute the child program.
!
- bufsize, if given, has the same meaning as the corresponding
argument to the built-in open() function: 0 means unbuffered, 1
--- 162,193 ----
This module defines one class called Popen:
! class Popen(args, bufsize=0, executable=None,
stdin=None, stdout=None, stderr=None,
! preexec_fn=None, close_fds=False,
! cwd=None, env=None, universal_newlines=False,
! startupinfo=None, creationflags=0):
!
!
! Arguments are:
!
- args should be a sequence of program arguments. The program to
execute is normally the first item in the args sequence, but can
! be explicitly set by using the executable argument.
!
! - On UNIX: the Popen class uses os.execvp() to execute the child
! program, which operates on sequences. If args is a string, it
! will be converted to a sequence using the cmdline2list method.
! Please note that syntax for quoting arguments is different from
! a typical UNIX shell. See the documentation of the cmdline2list
! method for more information.
!
! - On Windows: the Popen class uses CreateProcess() to execute the
! child program, which operates on strings. If args is a
! sequence, it will be converted to a string using the
! list2cmdline method. Please note that not all MS Windows
! applications interpret the command line the same way: The
! list2cmdline is designed for applications using the same rules
! as the MS C runtime.
!
- bufsize, if given, has the same meaning as the corresponding
argument to the built-in open() function: 0 means unbuffered, 1
***************
*** 160,165 ****
- If preexec_fn is set to a callable object, this object will be
! called in the child process just before the child is executed,
! with arguments preexec_args.
- If close_fds is true, all file descriptors except 0, 1 and 2
--- 209,213 ----
- If preexec_fn is set to a callable object, this object will be
! called in the child process just before the child is executed.
- If close_fds is true, all file descriptors except 0, 1 and 2
***************
*** 172,177 ****
new process.
! - If universal_newlines is true, the file objects fromchild and
! childerr are opened as a text files, but lines may be terminated
by any of '\n', the Unix end-of-line convention, '\r', the
Macintosh convention or '\r\n', the Windows convention. All of
--- 220,225 ----
new process.
! - If universal_newlines is true, the file objects stdout and
! stderr are opened as a text files, but lines may be terminated
by any of '\n', the Unix end-of-line convention, '\r', the
Macintosh convention or '\r\n', the Windows convention. All of
***************
*** 179,217 ****
program. Note: This feature is only available if Python is
built with universal newline support (the default). Also, the
! newlines attribute of the file objects fromchild, tochild and
! childerr are not updated by the communicate() method.
!
! The module also defines one shortcut function:
!
! run(*args):
! Run command with arguments. Wait for command to complete,
! then return the returncode attribute. Example:
!
! retcode = popen5.run("stty", "sane")
!
Exceptions
----------
Exceptions raised in the child process, before the new program has
! started to execute, will be re-raised in the parent. Additionally,
! the exception object will have one extra attribute called
! 'child_traceback', which is a string containing traceback
! information from the child's point of view.
!
The most common exception raised is OSError. This occurs, for
example, when trying to execute a non-existent file. Applications
should prepare for OSErrors.
!
! A PopenException will also be raised if Popen is called with
! invalid arguments.
!
!
Security
--------
! popen5 will never call /bin/sh implicitly. This means that all
! characters, including shell metacharacters, can safely be passed
! to child processes.
!
!
Popen objects
-------------
--- 227,286 ----
program. Note: This feature is only available if Python is
built with universal newline support (the default). Also, the
! newlines attribute of the file objects stdout, stdin and stderr
! are not updated by the communicate() method.
+ - The startupinfo and creationflags, if given, will be passed to
+ the underlying CreateProcess() function. They can specify
+ things such as appearance of the main window and priority for
+ the new process. (Windows only)
+
+
+ This module also defines two shortcut functions:
+
+ - call(*args, **kwargs):
+ Run command with arguments. Wait for command to complete, then
+ return the returncode attribute.
+
+ The arguments are the same as for the Popen constructor. Example:
+
+ retcode = call(["ls", "-l"])
+
+
+ - callv(*args, **kwargs):
+ Run command with arguments. Wait for command to complete, then
+ return the returncode attribute.
+
+ This function is identical to call(), except that each non-keyword
+ argument is treated as a program argument. Example:
+
+ retcode = callv("ls", "-l")
+
+ This is equivalent to:
+
+ retcode = call(["ls", "-l"])
+
+
Exceptions
----------
Exceptions raised in the child process, before the new program has
! started to execute, will be re-raised in the parent.
! Additionally, the exception object will have one extra attribute
! called 'child_traceback', which is a string containing traceback
! information from the childs point of view.
!
The most common exception raised is OSError. This occurs, for
example, when trying to execute a non-existent file. Applications
should prepare for OSErrors.
!
! A ValueError will be raised if Popen is called with invalid arguments.
!
!
Security
--------
! Unlike some other popen functions, this implementation will never call
! /bin/sh implicitly. This means that all characters, including shell
! metacharacters, can safely be passed to child processes.
!
!
Popen objects
-------------
***************
*** 219,234 ****
poll()
! Returns -1 if child process hasn't completed yet, or its exit
! status otherwise. See below for a description of how the exit
! status is encoded.
!
wait()
! Waits for and returns the exit status of the child process.
! The exit status encodes both the return code of the process
! and information about whether it exited using the exit()
! system call or died due to a signal. Functions to help
! interpret the status code are defined in the os module (the
! W*() family of functions).
!
communicate(input=None)
Interact with process: Send data to stdin. Read data from
--- 288,297 ----
poll()
! Check if child process has terminated. Returns returncode
! attribute.
!
wait()
! Wait for child process to terminate. Returns returncode attribute.
!
communicate(input=None)
Interact with process: Send data to stdin. Read data from
***************
*** 244,258 ****
The following attributes are also available:
!
! fromchild
! A file object that provides output from the child process.
!
! tochild
! A file object that provides input to the child process.
!
! childerr
! A file object that provides error output from the child
! process.
!
pid
The process ID of the child process.
--- 307,325 ----
The following attributes are also available:
!
! stdin
! If the stdin argument is PIPE, this attribute is a file object
! that provides input to the child process. Otherwise, it is None.
!
! stdout
! If the stdout argument is PIPE, this attribute is a file object
! that provides output from the child process. Otherwise, it is
! None.
!
! stderr
! If the stderr argument is PIPE, this attribute is file object that
! provides error output from the child process. Otherwise, it is
! None.
!
pid
The process ID of the child process.
***************
*** 260,272 ****
returncode
The child return code. A None value indicates that the
! process hasn't terminated yet. A negative value means that
! the process was terminated by a signal with number
! -returncode.
!
!
Open Issues
! Perhaps the module should be called something like "process",
! instead of "popen5".
--- 327,340 ----
returncode
The child return code. A None value indicates that the
! process hasn't terminated yet. A negative value -N indicates
! that the child was terminated by signal N (UNIX only).
!
!
Open Issues
! Currently, the reference implementation requires the "win32all"
! extensions when running on the Windows platform. This dependency
! could probably be eliminated by providing a small "glue" module
! written in C, just like the _winreg module.
Index: pep-0000.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0000.txt,v
retrieving revision 1.275
retrieving revision 1.276
diff -C2 -d -r1.275 -r1.276
*** pep-0000.txt 19 Jul 2004 18:08:56 -0000 1.275
--- pep-0000.txt 3 Aug 2004 13:13:43 -0000 1.276
***************
*** 120,124 ****
S 321 Date/Time Parsing and Formatting Kuchling
S 323 Copyable Iterators Martelli
! S 324 popen5 - New POSIX process module Astrand
S 325 Resource-Release Support for Generators Pedroni
S 330 Python Bytecode Verification Pelletier
--- 120,124 ----
S 321 Date/Time Parsing and Formatting Kuchling
S 323 Copyable Iterators Martelli
! S 324 process - New POSIX process module Astrand
S 325 Resource-Release Support for Generators Pedroni
S 330 Python Bytecode Verification Pelletier
***************
*** 348,352 ****
SF 322 Reverse Iteration Hettinger
S 323 Copyable Iterators Martelli
! S 324 popen5 - New POSIX process module Astrand
S 325 Resource-Release Support for Generators Pedroni
SR 326 A Case for Top and Bottom Values Carlson, Reedy
--- 348,352 ----
SF 322 Reverse Iteration Hettinger
S 323 Copyable Iterators Martelli
! S 324 process - New POSIX process module Astrand
S 325 Resource-Release Support for Generators Pedroni
SR 326 A Case for Top and Bottom Values Carlson, Reedy
More information about the Python-checkins
mailing list