Changeset 391 for python/trunk/Doc/library/os.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/os.rst
r2 r391 14 14 module. 15 15 16 The design of all built-in operating system dependent modules of Python is such 17 that as long as the same functionality is available, it uses the same interface; 18 for example, the function ``os.stat(path)`` returns stat information about 19 *path* in the same format (which happens to have originated with the POSIX 20 interface). 21 22 Extensions peculiar to a particular operating system are also available through 23 the :mod:`os` module, but using them is of course a threat to portability! 24 25 .. note:: 26 27 If not separately noted, all functions that claim "Availability: Unix" are 28 supported on Mac OS X, which builds on a Unix core. 16 Notes on the availability of these functions: 17 18 * The design of all built-in operating system dependent modules of Python is 19 such that as long as the same functionality is available, it uses the same 20 interface; for example, the function ``os.stat(path)`` returns stat 21 information about *path* in the same format (which happens to have originated 22 with the POSIX interface). 23 24 * Extensions peculiar to a particular operating system are also available 25 through the :mod:`os` module, but using them is of course a threat to 26 portability. 27 28 * An "Availability: Unix" note means that this function is commonly found on 29 Unix systems. It does not make any claims about its existence on a specific 30 operating system. 31 32 * If not separately noted, all functions that claim "Availability: Unix" are 33 supported on Mac OS X, which builds on a Unix core. 34 35 .. Availability notes get their own line and occur at the end of the function 36 .. documentation. 29 37 30 38 .. note:: … … 42 50 .. data:: name 43 51 44 The name of the operating system dependent module imported. The following names 45 have currently been registered: ``'posix'``, ``'nt'``, ``'mac'``, ``'os2'``, 46 ``'ce'``, ``'java'``, ``'riscos'``. 52 The name of the operating system dependent module imported. The following 53 names have currently been registered: ``'posix'``, ``'nt'``, 54 ``'os2'``, ``'ce'``, ``'java'``, ``'riscos'``. 55 56 .. seealso:: 57 :attr:`sys.platform` has a finer granularity. :func:`os.uname` gives 58 system-dependent version information. 59 60 The :mod:`platform` module provides detailed checks for the 61 system's identity. 47 62 48 63 … … 58 73 .. data:: environ 59 74 60 A mappingobject representing the string environment. For example,75 A :term:`mapping` object representing the string environment. For example, 61 76 ``environ['HOME']`` is the pathname of your home directory (on some platforms), 62 77 and is equivalent to ``getenv("HOME")`` in C. … … 80 95 On some platforms, including FreeBSD and Mac OS X, setting ``environ`` may 81 96 cause memory leaks. Refer to the system documentation for 82 :c func:`putenv`.97 :c:func:`putenv`. 83 98 84 99 If :func:`putenv` is not provided, a modified copy of this mapping may be … … 107 122 108 123 Return the filename corresponding to the controlling terminal of the process. 124 109 125 Availability: Unix. 110 126 … … 113 129 114 130 Return the effective group id of the current process. This corresponds to the 115 "set id" bit on the file being executed in the current process. Availability: 116 Unix. 131 "set id" bit on the file being executed in the current process. 132 133 Availability: Unix. 117 134 118 135 … … 121 138 .. index:: single: user; effective id 122 139 123 Return the current process's effective user id. Availability: Unix. 140 Return the current process's effective user id. 141 142 Availability: Unix. 124 143 125 144 … … 128 147 .. index:: single: process; group 129 148 130 Return the real group id of the current process. Availability: Unix. 149 Return the real group id of the current process. 150 151 Availability: Unix. 131 152 132 153 … … 134 155 135 156 Return list of supplemental group ids associated with the current process. 136 Availability: Unix. 157 158 Availability: Unix. 159 160 .. note:: On Mac OS X, :func:`getgroups` behavior differs somewhat from 161 other Unix platforms. If the Python interpreter was built with a 162 deployment target of :const:`10.5` or earlier, :func:`getgroups` returns 163 the list of effective group ids associated with the current user process; 164 this list is limited to a system-defined number of entries, typically 16, 165 and may be modified by calls to :func:`setgroups` if suitably privileged. 166 If built with a deployment target greater than :const:`10.5`, 167 :func:`getgroups` returns the current group access list for the user 168 associated with the effective user id of the process; the group access 169 list may change over the lifetime of the process, it is not affected by 170 calls to :func:`setgroups`, and its length is not limited to 16. The 171 deployment target value, :const:`MACOSX_DEPLOYMENT_TARGET`, can be 172 obtained with :func:`sysconfig.get_config_var`. 173 174 175 .. function:: initgroups(username, gid) 176 177 Call the system initgroups() to initialize the group access list with all of 178 the groups of which the specified username is a member, plus the specified 179 group id. 180 181 Availability: Unix. 182 183 .. versionadded:: 2.7 137 184 138 185 … … 143 190 :envvar:`LOGNAME` to find out who the user is, or 144 191 ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the currently 145 effective user id. Availability: Unix. 192 effective user id. 193 194 Availability: Unix. 146 195 147 196 … … 149 198 150 199 Return the process group id of the process with process id *pid*. If *pid* is 0, 151 the process group id of the current process is returned. Availability: Unix. 200 the process group id of the current process is returned. 201 202 Availability: Unix. 152 203 153 204 .. versionadded:: 2.3 … … 158 209 .. index:: single: process; group 159 210 160 Return the id of the current process group. Availability: Unix. 211 Return the id of the current process group. 212 213 Availability: Unix. 161 214 162 215 … … 165 218 .. index:: single: process; id 166 219 167 Return the current process id. Availability: Unix, Windows. 220 Return the current process id. 221 222 Availability: Unix, Windows. 168 223 169 224 … … 172 227 .. index:: single: process; id of parent 173 228 174 Return the parent's process id. Availability: Unix. 229 Return the parent's process id. 230 231 Availability: Unix. 232 233 234 .. function:: getresuid() 235 236 Return a tuple (ruid, euid, suid) denoting the current process's 237 real, effective, and saved user ids. 238 239 Availability: Unix. 240 241 .. versionadded:: 2.7 242 243 244 .. function:: getresgid() 245 246 Return a tuple (rgid, egid, sgid) denoting the current process's 247 real, effective, and saved group ids. 248 249 Availability: Unix. 250 251 .. versionadded:: 2.7 175 252 176 253 … … 179 256 .. index:: single: user; id 180 257 181 Return the current process's user id. Availability: Unix. 258 Return the current process's user id. 259 260 Availability: Unix. 182 261 183 262 … … 185 264 186 265 Return the value of the environment variable *varname* if it exists, or *value* 187 if it doesn't. *value* defaults to ``None``. Availability: most flavors of 188 Unix, Windows. 266 if it doesn't. *value* defaults to ``None``. 267 268 Availability: most flavors of Unix, Windows. 189 269 190 270 … … 195 275 Set the environment variable named *varname* to the string *value*. Such 196 276 changes to the environment affect subprocesses started with :func:`os.system`, 197 :func:`popen` or :func:`fork` and :func:`execv`. Availability: most flavors of 198 Unix, Windows. 277 :func:`popen` or :func:`fork` and :func:`execv`. 278 279 Availability: most flavors of Unix, Windows. 199 280 200 281 .. note:: … … 211 292 .. function:: setegid(egid) 212 293 213 Set the current process's effective group id. Availability: Unix. 294 Set the current process's effective group id. 295 296 Availability: Unix. 214 297 215 298 216 299 .. function:: seteuid(euid) 217 300 218 Set the current process's effective user id. Availability: Unix. 301 Set the current process's effective user id. 302 303 Availability: Unix. 219 304 220 305 221 306 .. function:: setgid(gid) 222 307 223 Set the current process' group id. Availability: Unix. 308 Set the current process' group id. 309 310 Availability: Unix. 224 311 225 312 … … 229 316 *groups*. *groups* must be a sequence, and each element must be an integer 230 317 identifying a group. This operation is typically available only to the superuser. 318 231 319 Availability: Unix. 232 320 233 321 .. versionadded:: 2.2 234 322 323 .. note:: On Mac OS X, the length of *groups* may not exceed the 324 system-defined maximum number of effective group ids, typically 16. 325 See the documentation for :func:`getgroups` for cases where it may not 326 return the same group list set by calling setgroups(). 235 327 236 328 .. function:: setpgrp() 237 329 238 Call the system call :c func:`setpgrp` or :cfunc:`setpgrp(0, 0)` depending on330 Call the system call :c:func:`setpgrp` or :c:func:`setpgrp(0, 0)` depending on 239 331 which version is implemented (if any). See the Unix manual for the semantics. 332 240 333 Availability: Unix. 241 334 … … 243 336 .. function:: setpgid(pid, pgrp) 244 337 245 Call the system call :c func:`setpgid` to set the process group id of the338 Call the system call :c:func:`setpgid` to set the process group id of the 246 339 process with id *pid* to the process group with id *pgrp*. See the Unix manual 247 for the semantics. Availability: Unix. 340 for the semantics. 341 342 Availability: Unix. 343 344 345 .. function:: setregid(rgid, egid) 346 347 Set the current process's real and effective group ids. 348 349 Availability: Unix. 350 351 352 .. function:: setresgid(rgid, egid, sgid) 353 354 Set the current process's real, effective, and saved group ids. 355 356 Availability: Unix. 357 358 .. versionadded:: 2.7 359 360 361 .. function:: setresuid(ruid, euid, suid) 362 363 Set the current process's real, effective, and saved user ids. 364 365 Availability: Unix. 366 367 .. versionadded:: 2.7 248 368 249 369 250 370 .. function:: setreuid(ruid, euid) 251 371 252 Set the current process's real and effective user ids. Availability: Unix. 253 254 255 .. function:: setregid(rgid, egid) 256 257 Set the current process's real and effective group ids. Availability: Unix. 372 Set the current process's real and effective user ids. 373 374 Availability: Unix. 258 375 259 376 260 377 .. function:: getsid(pid) 261 378 262 Call the system call :cfunc:`getsid`. See the Unix manual for the semantics. 379 Call the system call :c:func:`getsid`. See the Unix manual for the semantics. 380 263 381 Availability: Unix. 264 382 … … 268 386 .. function:: setsid() 269 387 270 Call the system call :cfunc:`setsid`. See the Unix manual for the semantics. 388 Call the system call :c:func:`setsid`. See the Unix manual for the semantics. 389 271 390 Availability: Unix. 272 391 … … 276 395 .. index:: single: user; id, setting 277 396 278 Set the current process's user id. Availability: Unix. 397 Set the current process's user id. 398 399 Availability: Unix. 279 400 280 401 … … 283 404 284 405 Return the error message corresponding to the error code in *code*. 285 On platforms where :cfunc:`strerror` returns ``NULL`` when given an unknown 286 error number, :exc:`ValueError` is raised. Availability: Unix, Windows. 406 On platforms where :c:func:`strerror` returns ``NULL`` when given an unknown 407 error number, :exc:`ValueError` is raised. 408 409 Availability: Unix, Windows. 287 410 288 411 289 412 .. function:: umask(mask) 290 413 291 Set the current numeric umask and return the previous umask. Availability: 292 Unix, Windows. 414 Set the current numeric umask and return the previous umask. 415 416 Availability: Unix, Windows. 293 417 294 418 … … 304 428 leading component; a better way to get the hostname is 305 429 :func:`socket.gethostname` or even 306 ``socket.gethostbyaddr(socket.gethostname())``. Availability: recent flavors of 307 Unix. 430 ``socket.gethostbyaddr(socket.gethostname())``. 431 432 Availability: recent flavors of Unix. 308 433 309 434 … … 314 439 Unset (delete) the environment variable named *varname*. Such changes to the 315 440 environment affect subprocesses started with :func:`os.system`, :func:`popen` or 316 :func:`fork` and :func:`execv`. Availability: most flavors of Unix, Windows.441 :func:`fork` and :func:`execv`. 317 442 318 443 When :func:`unsetenv` is supported, deletion of items in ``os.environ`` is … … 321 446 preferable to delete items of ``os.environ``. 322 447 448 Availability: most flavors of Unix, Windows. 449 323 450 324 451 .. _os-newstreams: … … 336 463 Return an open file object connected to the file descriptor *fd*. The *mode* 337 464 and *bufsize* arguments have the same meaning as the corresponding arguments to 338 the built-in :func:`open` function. Availability: Unix, Windows. 465 the built-in :func:`open` function. 466 467 Availability: Unix, Windows. 339 468 340 469 .. versionchanged:: 2.3 … … 344 473 .. versionchanged:: 2.5 345 474 On Unix, when the *mode* argument starts with ``'a'``, the *O_APPEND* flag is 346 set on the file descriptor (which the :c func:`fdopen` implementation already475 set on the file descriptor (which the :c:func:`fdopen` implementation already 347 476 does on most platforms). 348 477 … … 357 486 available as the return value of the :meth:`~file.close` method of the file object, 358 487 except that when the exit status is zero (termination without errors), ``None`` 359 is returned. Availability: Unix, Windows. 488 is returned. 489 490 Availability: Unix, Windows. 360 491 361 492 .. deprecated:: 2.6 … … 365 496 .. versionchanged:: 2.0 366 497 This function worked unreliably under Windows in earlier versions of Python. 367 This was due to the use of the :c func:`_popen` function from the libraries498 This was due to the use of the :c:func:`_popen` function from the libraries 368 499 provided with Windows. Newer versions of Python do not use the broken 369 500 implementation from the Windows libraries. … … 374 505 Return a new file object opened in update mode (``w+b``). The file has no 375 506 directory entries associated with it and will be automatically deleted once 376 there are no file descriptors for the file. Availability: Unix, 377 Windows. 507 there are no file descriptors for the file. 508 509 Availability: Unix, Windows. 378 510 379 511 There are a number of different :func:`popen\*` functions that provide slightly … … 468 600 by file descriptors. 469 601 602 The :meth:`~file.fileno` method can be used to obtain the file descriptor 603 associated with a file object when required. Note that using the file 604 descriptor directly will bypass the file object methods, ignoring aspects such 605 as internal buffering of data. 470 606 471 607 .. function:: close(fd) 472 608 473 Close file descriptor *fd*. Availability: Unix, Windows. 609 Close file descriptor *fd*. 610 611 Availability: Unix, Windows. 474 612 475 613 .. note:: … … 478 616 descriptor as returned by :func:`os.open` or :func:`pipe`. To close a "file 479 617 object" returned by the built-in function :func:`open` or by :func:`popen` or 480 :func:`fdopen`, use its :meth:`~ file.close` method.618 :func:`fdopen`, use its :meth:`~io.IOBase.close` method. 481 619 482 620 … … 484 622 485 623 Close all file descriptors from *fd_low* (inclusive) to *fd_high* (exclusive), 486 ignoring errors. Availability: Unix, Windows.Equivalent to::624 ignoring errors. Equivalent to:: 487 625 488 626 for fd in xrange(fd_low, fd_high): … … 492 630 pass 493 631 632 Availability: Unix, Windows. 633 494 634 .. versionadded:: 2.6 495 635 … … 497 637 .. function:: dup(fd) 498 638 499 Return a duplicate of file descriptor *fd*. Availability: Unix, 500 Windows. 639 Return a duplicate of file descriptor *fd*. 640 641 Availability: Unix, Windows. 501 642 502 643 … … 504 645 505 646 Duplicate file descriptor *fd* to *fd2*, closing the latter first if necessary. 647 506 648 Availability: Unix, Windows. 507 649 … … 510 652 511 653 Change the mode of the file given by *fd* to the numeric *mode*. See the docs 512 for :func:`chmod` for possible values of *mode*. Availability: Unix. 654 for :func:`chmod` for possible values of *mode*. 655 656 Availability: Unix. 513 657 514 658 .. versionadded:: 2.6 … … 519 663 Change the owner and group id of the file given by *fd* to the numeric *uid* 520 664 and *gid*. To leave one of the ids unchanged, set it to -1. 665 521 666 Availability: Unix. 522 667 … … 527 672 528 673 Force write of file with filedescriptor *fd* to disk. Does not force update of 529 metadata. Availability: Unix. 674 metadata. 675 676 Availability: Unix. 530 677 531 678 .. note:: … … 542 689 given in the ``pathconf_names`` dictionary. For configuration variables not 543 690 included in that mapping, passing an integer for *name* is also accepted. 544 Availability: Unix.545 691 546 692 If *name* is a string and is not known, :exc:`ValueError` is raised. If a … … 549 695 :const:`errno.EINVAL` for the error number. 550 696 697 Availability: Unix. 698 551 699 552 700 .. function:: fstat(fd) 553 701 554 Return status for file descriptor *fd*, like :func:`stat`. Availability: 555 Unix, Windows. 702 Return status for file descriptor *fd*, like :func:`~os.stat`. 703 704 Availability: Unix, Windows. 556 705 557 706 … … 559 708 560 709 Return information about the filesystem containing the file associated with file 561 descriptor *fd*, like :func:`statvfs`. Availability: Unix. 710 descriptor *fd*, like :func:`statvfs`. 711 712 Availability: Unix. 562 713 563 714 … … 565 716 566 717 Force write of file with filedescriptor *fd* to disk. On Unix, this calls the 567 native :c func:`fsync` function; on Windows, the MS :cfunc:`_commit` function.718 native :c:func:`fsync` function; on Windows, the MS :c:func:`_commit` function. 568 719 569 720 If you're starting with a Python file object *f*, first do ``f.flush()``, and 570 721 then do ``os.fsync(f.fileno())``, to ensure that all internal buffers associated 571 with *f* are written to disk. Availability: Unix, and Windows 572 starting in 2.2.3. 722 with *f* are written to disk. 723 724 Availability: Unix, and Windows starting in 2.2.3. 573 725 574 726 … … 576 728 577 729 Truncate the file corresponding to file descriptor *fd*, so that it is at most 578 *length* bytes in size. Availability: Unix. 730 *length* bytes in size. 731 732 Availability: Unix. 579 733 580 734 … … 582 736 583 737 Return ``True`` if the file descriptor *fd* is open and connected to a 584 tty(-like) device, else ``False``. Availability: Unix.738 tty(-like) device, else ``False``. 585 739 586 740 … … 590 744 by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the 591 745 beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the 592 current position; :const:`os.SEEK_END` or ``2`` to set it relative to the end of 593 the file. Availability: Unix, Windows. 746 current position; :const:`SEEK_END` or ``2`` to set it relative to the end of 747 the file. 748 749 Availability: Unix, Windows. 750 751 752 .. data:: SEEK_SET 753 SEEK_CUR 754 SEEK_END 755 756 Parameters to the :func:`lseek` function. Their values are 0, 1, and 2, 757 respectively. 758 759 Availability: Windows, Unix. 760 761 .. versionadded:: 2.5 594 762 595 763 … … 599 767 mode according to *mode*. The default *mode* is ``0777`` (octal), and the 600 768 current umask value is first masked out. Return the file descriptor for the 601 newly opened file. Availability: Unix, Windows.769 newly opened file. 602 770 603 771 For a description of the flag and mode values, see the C run-time documentation; 604 772 flag constants (like :const:`O_RDONLY` and :const:`O_WRONLY`) are defined in 605 this module too (see below). 773 this module too (see :ref:`open-constants`). In particular, on Windows adding 774 :const:`O_BINARY` is needed to open files in binary mode. 775 776 Availability: Unix, Windows. 606 777 607 778 .. note:: … … 619 790 Open a new pseudo-terminal pair. Return a pair of file descriptors ``(master, 620 791 slave)`` for the pty and the tty, respectively. For a (slightly) more portable 621 approach, use the :mod:`pty` module. Availability: some flavors of 622 Unix. 792 approach, use the :mod:`pty` module. 793 794 Availability: some flavors of Unix. 623 795 624 796 … … 626 798 627 799 Create a pipe. Return a pair of file descriptors ``(r, w)`` usable for reading 628 and writing, respectively. Availability: Unix, Windows. 800 and writing, respectively. 801 802 Availability: Unix, Windows. 629 803 630 804 … … 633 807 Read at most *n* bytes from file descriptor *fd*. Return a string containing the 634 808 bytes read. If the end of the file referred to by *fd* has been reached, an 635 empty string is returned. Availability: Unix, Windows. 809 empty string is returned. 810 811 Availability: Unix, Windows. 636 812 637 813 .. note:: … … 647 823 648 824 Return the process group associated with the terminal given by *fd* (an open 649 file descriptor as returned by :func:`os.open`). Availability: Unix. 825 file descriptor as returned by :func:`os.open`). 826 827 Availability: Unix. 650 828 651 829 … … 653 831 654 832 Set the process group associated with the terminal given by *fd* (an open file 655 descriptor as returned by :func:`os.open`) to *pg*. Availability: Unix. 833 descriptor as returned by :func:`os.open`) to *pg*. 834 835 Availability: Unix. 656 836 657 837 … … 660 840 Return a string which specifies the terminal device associated with 661 841 file descriptor *fd*. If *fd* is not associated with a terminal device, an 662 exception is raised. Availability: Unix. 842 exception is raised. 843 844 Availability: Unix. 663 845 664 846 … … 666 848 667 849 Write the string *str* to file descriptor *fd*. Return the number of bytes 668 actually written. Availability: Unix, Windows. 850 actually written. 851 852 Availability: Unix, Windows. 669 853 670 854 .. note:: … … 675 859 :func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its 676 860 :meth:`~file.write` method. 861 862 863 .. _open-constants: 864 865 ``open()`` flag constants 866 ~~~~~~~~~~~~~~~~~~~~~~~~~ 677 867 678 868 The following constants are options for the *flags* parameter to the … … 727 917 728 918 729 .. data:: SEEK_SET730 SEEK_CUR731 SEEK_END732 733 Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,734 respectively. Availability: Windows, Unix.735 736 .. versionadded:: 2.5737 738 739 919 .. _os-file-dir: 740 920 … … 751 931 :const:`X_OK` to test permissions. Return :const:`True` if access is allowed, 752 932 :const:`False` if not. See the Unix man page :manpage:`access(2)` for more 753 information. Availability: Unix, Windows. 933 information. 934 935 Availability: Unix, Windows. 754 936 755 937 .. note:: … … 758 940 before actually doing so using :func:`open` creates a security hole, 759 941 because the user might exploit the short time interval between checking 760 and opening the file to manipulate it. 942 and opening the file to manipulate it. It's preferable to use :term:`EAFP` 943 techniques. For example:: 944 945 if os.access("myfile", os.R_OK): 946 with open("myfile") as fp: 947 return fp.read() 948 return "some default data" 949 950 is better written as:: 951 952 try: 953 fp = open("myfile") 954 except IOError as e: 955 if e.errno == errno.EACCES: 956 return "some default data" 957 # Not a permission error. 958 raise 959 else: 960 with fp: 961 return fp.read() 761 962 762 963 .. note:: … … 795 996 .. index:: single: directory; changing 796 997 797 Change the current working directory to *path*. Availability: Unix, 798 Windows. 998 Change the current working directory to *path*. 999 1000 Availability: Unix, Windows. 799 1001 800 1002 … … 803 1005 Change the current working directory to the directory represented by the file 804 1006 descriptor *fd*. The descriptor must refer to an opened directory, not an open 805 file. Availability: Unix. 1007 file. 1008 1009 Availability: Unix. 806 1010 807 1011 .. versionadded:: 2.3 … … 810 1014 .. function:: getcwd() 811 1015 812 Return a string representing the current working directory. Availability: 813 Unix, Windows. 1016 Return a string representing the current working directory. 1017 1018 Availability: Unix, Windows. 814 1019 815 1020 … … 817 1022 818 1023 Return a Unicode object representing the current working directory. 1024 819 1025 Availability: Unix, Windows. 820 1026 … … 827 1033 (bitwise OR) of the following values (as defined in the :mod:`stat` module): 828 1034 829 * ``UF_NODUMP`` 830 * ``UF_IMMUTABLE`` 831 * ``UF_APPEND`` 832 * ``UF_OPAQUE`` 833 * ``UF_NOUNLINK`` 834 * ``SF_ARCHIVED`` 835 * ``SF_IMMUTABLE`` 836 * ``SF_APPEND`` 837 * ``SF_NOUNLINK`` 838 * ``SF_SNAPSHOT`` 1035 * :data:`stat.UF_NODUMP` 1036 * :data:`stat.UF_IMMUTABLE` 1037 * :data:`stat.UF_APPEND` 1038 * :data:`stat.UF_OPAQUE` 1039 * :data:`stat.UF_NOUNLINK` 1040 * :data:`stat.UF_COMPRESSED` 1041 * :data:`stat.UF_HIDDEN` 1042 * :data:`stat.SF_ARCHIVED` 1043 * :data:`stat.SF_IMMUTABLE` 1044 * :data:`stat.SF_APPEND` 1045 * :data:`stat.SF_NOUNLINK` 1046 * :data:`stat.SF_SNAPSHOT` 839 1047 840 1048 Availability: Unix. … … 891 1099 892 1100 Change the owner and group id of *path* to the numeric *uid* and *gid*. To leave 893 one of the ids unchanged, set it to -1. Availability: Unix. 1101 one of the ids unchanged, set it to -1. 1102 1103 Availability: Unix. 894 1104 895 1105 … … 897 1107 898 1108 Set the flags of *path* to the numeric *flags*, like :func:`chflags`, but do not 899 follow symbolic links. Availability: Unix. 1109 follow symbolic links. 1110 1111 Availability: Unix. 900 1112 901 1113 .. versionadded:: 2.6 … … 906 1118 Change the mode of *path* to the numeric *mode*. If path is a symlink, this 907 1119 affects the symlink rather than the target. See the docs for :func:`chmod` 908 for possible values of *mode*. Availability: Unix. 1120 for possible values of *mode*. 1121 1122 Availability: Unix. 909 1123 910 1124 .. versionadded:: 2.6 … … 914 1128 915 1129 Change the owner and group id of *path* to the numeric *uid* and *gid*. This 916 function will not follow symbolic links. Availability: Unix. 1130 function will not follow symbolic links. 1131 1132 Availability: Unix. 917 1133 918 1134 .. versionadded:: 2.3 … … 921 1137 .. function:: link(source, link_name) 922 1138 923 Create a hard link pointing to *source* named *link_name*. Availability: 924 Unix. 1139 Create a hard link pointing to *source* named *link_name*. 1140 1141 Availability: Unix. 925 1142 926 1143 … … 930 1147 *path*. The list is in arbitrary order. It does not include the special 931 1148 entries ``'.'`` and ``'..'`` even if they are present in the 932 directory. Availability: Unix, Windows. 1149 directory. 1150 1151 Availability: Unix, Windows. 933 1152 934 1153 .. versionchanged:: 2.3 … … 940 1159 .. function:: lstat(path) 941 1160 942 Like :func:`stat`, but do not follow symbolic links. This is an alias for 943 :func:`stat` on platforms that do not support symbolic links, such as 944 Windows. 1161 Perform the equivalent of an :c:func:`lstat` system call on the given path. 1162 Similar to :func:`~os.stat`, but does not follow symbolic links. On 1163 platforms that do not support symbolic links, this is an alias for 1164 :func:`~os.stat`. 945 1165 946 1166 … … 949 1169 Create a FIFO (a named pipe) named *path* with numeric mode *mode*. The default 950 1170 *mode* is ``0666`` (octal). The current umask value is first masked out from 951 the mode. Availability: Unix. 1171 the mode. 1172 1173 Availability: Unix. 952 1174 953 1175 FIFOs are pipes that can be accessed like regular files. FIFOs exist until they … … 958 1180 959 1181 960 .. function:: mknod(filename[, mode=0600 , device])1182 .. function:: mknod(filename[, mode=0600[, device=0]]) 961 1183 962 1184 Create a filesystem node (file, device special file or named pipe) named … … 975 1197 976 1198 Extract the device major number from a raw device number (usually the 977 :attr:`st_dev` or :attr:`st_rdev` field from :c type:`stat`).1199 :attr:`st_dev` or :attr:`st_rdev` field from :c:type:`stat`). 978 1200 979 1201 .. versionadded:: 2.3 … … 983 1205 984 1206 Extract the device minor number from a raw device number (usually the 985 :attr:`st_dev` or :attr:`st_rdev` field from :c type:`stat`).1207 :attr:`st_dev` or :attr:`st_rdev` field from :c:type:`stat`). 986 1208 987 1209 .. versionadded:: 2.3 … … 999 1221 Create a directory named *path* with numeric mode *mode*. The default *mode* is 1000 1222 ``0777`` (octal). On some systems, *mode* is ignored. Where it is used, the 1001 current umask value is first masked out. Availability: Unix, Windows. 1223 current umask value is first masked out. If the directory already exists, 1224 :exc:`OSError` is raised. 1002 1225 1003 1226 It is also possible to create temporary directories; see the 1004 1227 :mod:`tempfile` module's :func:`tempfile.mkdtemp` function. 1228 1229 Availability: Unix, Windows. 1005 1230 1006 1231 … … 1012 1237 1013 1238 Recursive directory creation function. Like :func:`mkdir`, but makes all 1014 intermediate-level directories needed to contain the leaf directory. Throws an1239 intermediate-level directories needed to contain the leaf directory. Raises an 1015 1240 :exc:`error` exception if the leaf directory already exists or cannot be 1016 1241 created. The default *mode* is ``0777`` (octal). On some systems, *mode* is … … 1037 1262 given in the ``pathconf_names`` dictionary. For configuration variables not 1038 1263 included in that mapping, passing an integer for *name* is also accepted. 1039 Availability: Unix.1040 1264 1041 1265 If *name* is a string and is not known, :exc:`ValueError` is raised. If a … … 1043 1267 included in ``pathconf_names``, an :exc:`OSError` is raised with 1044 1268 :const:`errno.EINVAL` for the error number. 1269 1270 Availability: Unix. 1045 1271 1046 1272 … … 1073 1299 remove a file that is in use causes an exception to be raised; on Unix, the 1074 1300 directory entry is removed but the storage allocated to the file is not made 1075 available until the original file is no longer in use. Availability: Unix, 1076 Windows. 1301 available until the original file is no longer in use. 1302 1303 Availability: Unix, Windows. 1077 1304 1078 1305 … … 1102 1329 Windows, if *dst* already exists, :exc:`OSError` will be raised even if it is a 1103 1330 file; there may be no way to implement an atomic rename when *dst* names an 1104 existing file. Availability: Unix, Windows. 1331 existing file. 1332 1333 Availability: Unix, Windows. 1105 1334 1106 1335 … … 1124 1353 Remove (delete) the directory *path*. Only works when the directory is 1125 1354 empty, otherwise, :exc:`OSError` is raised. In order to remove whole 1126 directory trees, :func:`shutil.rmtree` can be used. Availability: Unix, 1127 Windows. 1355 directory trees, :func:`shutil.rmtree` can be used. 1356 1357 Availability: Unix, Windows. 1128 1358 1129 1359 1130 1360 .. function:: stat(path) 1131 1361 1132 Perform a :cfunc:`stat` system call on the given path. The return value is an1133 object whose attributes correspond to the members of the :ctype:`stat`1134 structure, namely: :attr:`st_mode` (protection bits), :attr:`st_ino` (inode 1135 number), :attr:`st_dev` (device), :attr:`st_nlink` (number of hard links),1136 :attr:`st_uid` (user id of owner), :attr:`st_gid` (group id of owner),1137 :attr:`st_size` (size of file, in bytes), :attr:`st_atime` (time of most recent 1138 access), :attr:`st_mtime` (time of most recent content modification),1139 :attr:`st_ctime` (platform dependent; time of most recent metadata change on1140 Unix, or the time of creation on Windows)::1141 1142 >>> import os1143 >>> statinfo = os.stat('somefile.txt')1144 >>> statinfo1145 (33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732)1146 >>> statinfo.st_size1147 926L1148 >>>1362 Perform the equivalent of a :c:func:`stat` system call on the given path. 1363 (This function follows symlinks; to stat a symlink use :func:`lstat`.) 1364 1365 The return value is an object whose attributes correspond to the members 1366 of the :c:type:`stat` structure, namely: 1367 1368 * :attr:`st_mode` - protection bits, 1369 * :attr:`st_ino` - inode number, 1370 * :attr:`st_dev` - device, 1371 * :attr:`st_nlink` - number of hard links, 1372 * :attr:`st_uid` - user id of owner, 1373 * :attr:`st_gid` - group id of owner, 1374 * :attr:`st_size` - size of file, in bytes, 1375 * :attr:`st_atime` - time of most recent access, 1376 * :attr:`st_mtime` - time of most recent content modification, 1377 * :attr:`st_ctime` - platform dependent; time of most recent metadata change on 1378 Unix, or the time of creation on Windows) 1149 1379 1150 1380 .. versionchanged:: 2.3 … … 1155 1385 1156 1386 On some Unix systems (such as Linux), the following attributes may also be 1157 available: :attr:`st_blocks` (number of blocks allocated for file), 1158 :attr:`st_blksize` (filesystem blocksize), :attr:`st_rdev` (type of device if an 1159 inode device). :attr:`st_flags` (user defined flags for file). 1387 available: 1388 1389 * :attr:`st_blocks` - number of 512-byte blocks allocated for file 1390 * :attr:`st_blksize` - filesystem blocksize for efficient file system I/O 1391 * :attr:`st_rdev` - type of device if an inode device 1392 * :attr:`st_flags` - user defined flags for file 1160 1393 1161 1394 On other Unix systems (such as FreeBSD), the following attributes may be 1162 available (but may be only filled out if root tries to use them): :attr:`st_gen` 1163 (file generation number), :attr:`st_birthtime` (time of file creation). 1395 available (but may be only filled out if root tries to use them): 1396 1397 * :attr:`st_gen` - file generation number 1398 * :attr:`st_birthtime` - time of file creation 1164 1399 1165 1400 On Mac OS systems, the following attributes may also be available: 1166 :attr:`st_rsize`, :attr:`st_creator`, :attr:`st_type`. 1167 1168 On RISCOS systems, the following attributes are also available: :attr:`st_ftype` 1169 (file type), :attr:`st_attrs` (attributes), :attr:`st_obtype` (object type). 1170 1171 .. index:: module: stat 1172 1173 For backward compatibility, the return value of :func:`stat` is also accessible 1401 1402 * :attr:`st_rsize` 1403 * :attr:`st_creator` 1404 * :attr:`st_type` 1405 1406 On RISCOS systems, the following attributes are also available: 1407 1408 * :attr:`st_ftype` (file type) 1409 * :attr:`st_attrs` (attributes) 1410 * :attr:`st_obtype` (object type). 1411 1412 .. note:: 1413 1414 The exact meaning and resolution of the :attr:`st_atime`, 1415 :attr:`st_mtime`, and :attr:`st_ctime` attributes depend on the operating 1416 system and the file system. For example, on Windows systems using the FAT 1417 or FAT32 file systems, :attr:`st_mtime` has 2-second resolution, and 1418 :attr:`st_atime` has only 1-day resolution. See your operating system 1419 documentation for details. 1420 1421 For backward compatibility, the return value of :func:`~os.stat` is also accessible 1174 1422 as a tuple of at least 10 integers giving the most important (and portable) 1175 members of the :c type:`stat` structure, in the order :attr:`st_mode`,1423 members of the :c:type:`stat` structure, in the order :attr:`st_mode`, 1176 1424 :attr:`st_ino`, :attr:`st_dev`, :attr:`st_nlink`, :attr:`st_uid`, 1177 1425 :attr:`st_gid`, :attr:`st_size`, :attr:`st_atime`, :attr:`st_mtime`, 1178 1426 :attr:`st_ctime`. More items may be added at the end by some implementations. 1427 1428 .. index:: module: stat 1429 1179 1430 The standard module :mod:`stat` defines functions and constants that are useful 1180 for extracting information from a :c type:`stat` structure. (On Windows, some1431 for extracting information from a :c:type:`stat` structure. (On Windows, some 1181 1432 items are filled with dummy values.) 1182 1433 1183 .. note:: 1184 1185 The exact meaning and resolution of the :attr:`st_atime`, :attr:`st_mtime`, and 1186 :attr:`st_ctime` members depends on the operating system and the file system. 1187 For example, on Windows systems using the FAT or FAT32 file systems, 1188 :attr:`st_mtime` has 2-second resolution, and :attr:`st_atime` has only 1-day 1189 resolution. See your operating system documentation for details. 1434 Example:: 1435 1436 >>> import os 1437 >>> statinfo = os.stat('somefile.txt') 1438 >>> statinfo 1439 (33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732) 1440 >>> statinfo.st_size 1441 926 1190 1442 1191 1443 Availability: Unix, Windows. … … 1201 1453 1202 1454 Determine whether :class:`stat_result` represents time stamps as float objects. 1203 If *newvalue* is ``True``, future calls to :func:` stat` return floats, if it is1455 If *newvalue* is ``True``, future calls to :func:`~os.stat` return floats, if it is 1204 1456 ``False``, future calls return ints. If *newvalue* is omitted, return the 1205 1457 current setting. … … 1226 1478 .. function:: statvfs(path) 1227 1479 1228 Perform a :c func:`statvfs` system call on the given path. The return value is1480 Perform a :c:func:`statvfs` system call on the given path. The return value is 1229 1481 an object whose attributes describe the filesystem on the given path, and 1230 correspond to the members of the :c type:`statvfs` structure, namely:1482 correspond to the members of the :c:type:`statvfs` structure, namely: 1231 1483 :attr:`f_bsize`, :attr:`f_frsize`, :attr:`f_blocks`, :attr:`f_bfree`, 1232 1484 :attr:`f_bavail`, :attr:`f_files`, :attr:`f_ffree`, :attr:`f_favail`, 1233 :attr:`f_flag`, :attr:`f_namemax`. Availability: Unix.1485 :attr:`f_flag`, :attr:`f_namemax`. 1234 1486 1235 1487 .. index:: module: statvfs … … 1238 1490 values correspond to the attributes, in the order given above. The standard 1239 1491 module :mod:`statvfs` defines constants that are useful for extracting 1240 information from a :c type:`statvfs` structure when accessing it as a sequence;1492 information from a :c:type:`statvfs` structure when accessing it as a sequence; 1241 1493 this remains useful when writing code that needs to work with versions of Python 1242 1494 that don't support accessing the fields as attributes. 1243 1495 1496 Availability: Unix. 1497 1244 1498 .. versionchanged:: 2.2 1245 1499 Added access to values as attributes of the returned object. … … 1248 1502 .. function:: symlink(source, link_name) 1249 1503 1250 Create a symbolic link pointing to *source* named *link_name*. Availability: 1251 Unix. 1504 Create a symbolic link pointing to *source* named *link_name*. 1505 1506 Availability: Unix. 1252 1507 1253 1508 … … 1303 1558 Remove (delete) the file *path*. This is the same function as 1304 1559 :func:`remove`; the :func:`unlink` name is its traditional Unix 1305 name. Availability: Unix, Windows. 1560 name. 1561 1562 Availability: Unix, Windows. 1306 1563 1307 1564 … … 1316 1573 the operating system implements directories as files (for example, Windows 1317 1574 does not). Note that the exact times you set here may not be returned by a 1318 subsequent :func:` stat` call, depending on the resolution with which your1319 operating system records access and modification times; see :func:` stat`.1575 subsequent :func:`~os.stat` call, depending on the resolution with which your 1576 operating system records access and modification times; see :func:`~os.stat`. 1320 1577 1321 1578 .. versionchanged:: 2.0 … … 1325 1582 1326 1583 1327 .. function:: walk(top [, topdown=True [, onerror=None[, followlinks=False]]])1584 .. function:: walk(top, topdown=True, onerror=None, followlinks=False) 1328 1585 1329 1586 .. index:: … … 1358 1615 generated before *dirpath* itself is generated. 1359 1616 1360 By default errors from the :func:`listdir` call are ignored. If optional1617 By default, errors from the :func:`listdir` call are ignored. If optional 1361 1618 argument *onerror* is specified, it should be a function; it will be called with 1362 1619 one argument, an :exc:`OSError` instance. It can report the error to continue … … 1420 1677 These functions may be used to create and manage processes. 1421 1678 1422 The various :func:`exec\* ` functions take a list of arguments for the new1679 The various :func:`exec\* <execl>` functions take a list of arguments for the new 1423 1680 program loaded into the process. In each case, the first of these arguments is 1424 1681 passed to the new program as its own name rather than as an argument a user may 1425 1682 have typed on a command line. For the C programmer, this is the ``argv[0]`` 1426 passed to a program's :c func:`main`. For example, ``os.execv('/bin/echo',1683 passed to a program's :c:func:`main`. For example, ``os.execv('/bin/echo', 1427 1684 ['foo', 'bar'])`` will only print ``bar`` on standard output; ``foo`` will seem 1428 1685 to be ignored. … … 1433 1690 Generate a :const:`SIGABRT` signal to the current process. On Unix, the default 1434 1691 behavior is to produce a core dump; on Windows, the process immediately returns 1435 an exit code of ``3``. Be aware that programs which use :func:`signal.signal` 1436 to register a handler for :const:`SIGABRT` will behave differently. 1692 an exit code of ``3``. Be aware that calling this function will not call the 1693 Python signal handler registered for :const:`SIGABRT` with 1694 :func:`signal.signal`. 1695 1437 1696 Availability: Unix, Windows. 1438 1697 … … 1456 1715 on these open files, you should flush them using 1457 1716 :func:`sys.stdout.flush` or :func:`os.fsync` before calling an 1458 :func:`exec\* ` function.1459 1460 The "l" and "v" variants of the :func:`exec\* ` functions differ in how1717 :func:`exec\* <execl>` function. 1718 1719 The "l" and "v" variants of the :func:`exec\* <execl>` functions differ in how 1461 1720 command-line arguments are passed. The "l" variants are perhaps the easiest 1462 1721 to work with if the number of parameters is fixed when the code is written; the … … 1470 1729 :func:`execlpe`, :func:`execvp`, and :func:`execvpe`) will use the 1471 1730 :envvar:`PATH` environment variable to locate the program *file*. When the 1472 environment is being replaced (using one of the :func:`exec\*e ` variants,1731 environment is being replaced (using one of the :func:`exec\*e <execl>` variants, 1473 1732 discussed in the next paragraph), the new environment is used as the source of 1474 1733 the :envvar:`PATH` variable. The other variants, :func:`execl`, :func:`execle`, … … 1489 1748 .. function:: _exit(n) 1490 1749 1491 Exit to the system with status *n*, without calling cleanup handlers, flushing 1492 stdio buffers, etc. Availability: Unix, Windows. 1750 Exit the process with status *n*, without calling cleanup handlers, flushing 1751 stdio buffers, etc. 1752 1753 Availability: Unix, Windows. 1493 1754 1494 1755 .. note:: 1495 1756 1496 The standard way to exit is ``sys.exit(n)``. :func:`_exit` should normally only1497 be used in the child process after a :func:`fork`.1757 The standard way to exit is ``sys.exit(n)``. :func:`_exit` should 1758 normally only be used in the child process after a :func:`fork`. 1498 1759 1499 1760 The following exit codes are defined and can be used with :func:`_exit`, … … 1510 1771 .. data:: EX_OK 1511 1772 1512 Exit code that means no error occurred. Availability: Unix. 1773 Exit code that means no error occurred. 1774 1775 Availability: Unix. 1513 1776 1514 1777 .. versionadded:: 2.3 … … 1518 1781 1519 1782 Exit code that means the command was used incorrectly, such as when the wrong 1520 number of arguments are given. Availability: Unix. 1783 number of arguments are given. 1784 1785 Availability: Unix. 1521 1786 1522 1787 .. versionadded:: 2.3 … … 1525 1790 .. data:: EX_DATAERR 1526 1791 1527 Exit code that means the input data was incorrect. Availability: Unix. 1792 Exit code that means the input data was incorrect. 1793 1794 Availability: Unix. 1528 1795 1529 1796 .. versionadded:: 2.3 … … 1533 1800 1534 1801 Exit code that means an input file did not exist or was not readable. 1802 1535 1803 Availability: Unix. 1536 1804 … … 1540 1808 .. data:: EX_NOUSER 1541 1809 1542 Exit code that means a specified user did not exist. Availability: Unix. 1810 Exit code that means a specified user did not exist. 1811 1812 Availability: Unix. 1543 1813 1544 1814 .. versionadded:: 2.3 … … 1547 1817 .. data:: EX_NOHOST 1548 1818 1549 Exit code that means a specified host did not exist. Availability: Unix. 1819 Exit code that means a specified host did not exist. 1820 1821 Availability: Unix. 1550 1822 1551 1823 .. versionadded:: 2.3 … … 1554 1826 .. data:: EX_UNAVAILABLE 1555 1827 1556 Exit code that means that a required service is unavailable. Availability: 1557 Unix. 1828 Exit code that means that a required service is unavailable. 1829 1830 Availability: Unix. 1558 1831 1559 1832 .. versionadded:: 2.3 … … 1562 1835 .. data:: EX_SOFTWARE 1563 1836 1564 Exit code that means an internal software error was detected. Availability: 1565 Unix. 1837 Exit code that means an internal software error was detected. 1838 1839 Availability: Unix. 1566 1840 1567 1841 .. versionadded:: 2.3 … … 1571 1845 1572 1846 Exit code that means an operating system error was detected, such as the 1573 inability to fork or create a pipe. Availability: Unix. 1847 inability to fork or create a pipe. 1848 1849 Availability: Unix. 1574 1850 1575 1851 .. versionadded:: 2.3 … … 1579 1855 1580 1856 Exit code that means some system file did not exist, could not be opened, or had 1581 some other kind of error. Availability: Unix. 1857 some other kind of error. 1858 1859 Availability: Unix. 1582 1860 1583 1861 .. versionadded:: 2.3 … … 1587 1865 1588 1866 Exit code that means a user specified output file could not be created. 1867 1589 1868 Availability: Unix. 1590 1869 … … 1595 1874 1596 1875 Exit code that means that an error occurred while doing I/O on some file. 1876 1597 1877 Availability: Unix. 1598 1878 … … 1604 1884 Exit code that means a temporary failure occurred. This indicates something 1605 1885 that may not really be an error, such as a network connection that couldn't be 1606 made during a retryable operation. Availability: Unix. 1886 made during a retryable operation. 1887 1888 Availability: Unix. 1607 1889 1608 1890 .. versionadded:: 2.3 … … 1612 1894 1613 1895 Exit code that means that a protocol exchange was illegal, invalid, or not 1614 understood. Availability: Unix. 1896 understood. 1897 1898 Availability: Unix. 1615 1899 1616 1900 .. versionadded:: 2.3 … … 1620 1904 1621 1905 Exit code that means that there were insufficient permissions to perform the 1622 operation (but not intended for file system problems). Availability: Unix. 1906 operation (but not intended for file system problems). 1907 1908 Availability: Unix. 1623 1909 1624 1910 .. versionadded:: 2.3 … … 1628 1914 1629 1915 Exit code that means that some kind of configuration error occurred. 1916 1630 1917 Availability: Unix. 1631 1918 … … 1635 1922 .. data:: EX_NOTFOUND 1636 1923 1637 Exit code that means something like "an entry was not found". Availability: 1638 Unix. 1924 Exit code that means something like "an entry was not found". 1925 1926 Availability: Unix. 1639 1927 1640 1928 .. versionadded:: 2.3 … … 1659 1947 master end of the pseudo-terminal. For a more portable approach, use the 1660 1948 :mod:`pty` module. If an error occurs :exc:`OSError` is raised. 1949 1661 1950 Availability: some flavors of Unix. 1662 1951 … … 1670 1959 Send signal *sig* to the process *pid*. Constants for the specific signals 1671 1960 available on the host platform are defined in the :mod:`signal` module. 1672 Availability: Unix. 1961 1962 Windows: The :data:`signal.CTRL_C_EVENT` and 1963 :data:`signal.CTRL_BREAK_EVENT` signals are special signals which can 1964 only be sent to console processes which share a common console window, 1965 e.g., some subprocesses. Any other value for *sig* will cause the process 1966 to be unconditionally killed by the TerminateProcess API, and the exit code 1967 will be set to *sig*. The Windows version of :func:`kill` additionally takes 1968 process handles to be killed. 1969 1970 .. versionadded:: 2.7 Windows support 1673 1971 1674 1972 … … 1679 1977 single: process; signalling 1680 1978 1681 Send the signal *sig* to the process group *pgid*. Availability: Unix. 1979 Send the signal *sig* to the process group *pgid*. 1980 1981 Availability: Unix. 1682 1982 1683 1983 .. versionadded:: 2.3 … … 1687 1987 1688 1988 Add *increment* to the process's "niceness". Return the new niceness. 1989 1689 1990 Availability: Unix. 1690 1991 … … 1693 1994 1694 1995 Lock program segments into memory. The value of *op* (defined in 1695 ``<sys/lock.h>``) determines which segments are locked. Availability: Unix. 1996 ``<sys/lock.h>``) determines which segments are locked. 1997 1998 Availability: Unix. 1696 1999 1697 2000 … … 1728 2031 be used with the :func:`waitpid` function. 1729 2032 1730 The "l" and "v" variants of the :func:`spawn\* ` functions differ in how2033 The "l" and "v" variants of the :func:`spawn\* <spawnl>` functions differ in how 1731 2034 command-line arguments are passed. The "l" variants are perhaps the easiest 1732 2035 to work with if the number of parameters is fixed when the code is written; the … … 1740 2043 :func:`spawnlpe`, :func:`spawnvp`, and :func:`spawnvpe`) will use the 1741 2044 :envvar:`PATH` environment variable to locate the program *file*. When the 1742 environment is being replaced (using one of the :func:`spawn\*e ` variants,2045 environment is being replaced (using one of the :func:`spawn\*e <spawnl>` variants, 1743 2046 discussed in the next paragraph), the new environment is used as the source of 1744 2047 the :envvar:`PATH` variable. The other variants, :func:`spawnl`, … … 1766 2069 1767 2070 Availability: Unix, Windows. :func:`spawnlp`, :func:`spawnlpe`, :func:`spawnvp` 1768 and :func:`spawnvpe` are not available on Windows. 2071 and :func:`spawnvpe` are not available on Windows. :func:`spawnle` and 2072 :func:`spawnve` are not thread-safe on Windows; we advise you to use the 2073 :mod:`subprocess` module instead. 1769 2074 1770 2075 .. versionadded:: 1.6 … … 1774 2079 P_NOWAITO 1775 2080 1776 Possible values for the *mode* parameter to the :func:`spawn\* ` family of2081 Possible values for the *mode* parameter to the :func:`spawn\* <spawnl>` family of 1777 2082 functions. If either of these values is given, the :func:`spawn\*` functions 1778 2083 will return as soon as the new process has been created, with the process id as 1779 the return value. Availability: Unix, Windows. 2084 the return value. 2085 2086 Availability: Unix, Windows. 1780 2087 1781 2088 .. versionadded:: 1.6 … … 1784 2091 .. data:: P_WAIT 1785 2092 1786 Possible value for the *mode* parameter to the :func:`spawn\* ` family of2093 Possible value for the *mode* parameter to the :func:`spawn\* <spawnl>` family of 1787 2094 functions. If this is given as *mode*, the :func:`spawn\*` functions will not 1788 2095 return until the new process has run to completion and will return the exit code 1789 2096 of the process the run is successful, or ``-signal`` if a signal kills the 1790 process. Availability: Unix, Windows. 2097 process. 2098 2099 Availability: Unix, Windows. 1791 2100 1792 2101 .. versionadded:: 1.6 … … 1796 2105 P_OVERLAY 1797 2106 1798 Possible values for the *mode* parameter to the :func:`spawn\* ` family of2107 Possible values for the *mode* parameter to the :func:`spawn\* <spawnl>` family of 1799 2108 functions. These are less portable than those listed above. :const:`P_DETACH` 1800 2109 is similar to :const:`P_NOWAIT`, but the new process is detached from the 1801 2110 console of the calling process. If :const:`P_OVERLAY` is used, the current 1802 2111 process will be replaced; the :func:`spawn\*` function will not return. 2112 1803 2113 Availability: Windows. 1804 2114 … … 1824 2134 the application's exit status. The *path* parameter is relative to the current 1825 2135 directory. If you want to use an absolute path, make sure the first character 1826 is not a slash (``'/'``); the underlying Win32 :c func:`ShellExecute` function2136 is not a slash (``'/'``); the underlying Win32 :c:func:`ShellExecute` function 1827 2137 doesn't work if it is. Use the :func:`os.path.normpath` function to ensure that 1828 the path is properly encoded for Win32. Availability: Windows. 2138 the path is properly encoded for Win32. 2139 2140 Availability: Windows. 1829 2141 1830 2142 .. versionadded:: 2.0 … … 1837 2149 1838 2150 Execute the command (a string) in a subshell. This is implemented by calling 1839 the Standard C function :c func:`system`, and has the same limitations.2151 the Standard C function :c:func:`system`, and has the same limitations. 1840 2152 Changes to :data:`sys.stdin`, etc. are not reflected in the environment of the 1841 2153 executed command. … … 1843 2155 On Unix, the return value is the exit status of the process encoded in the 1844 2156 format specified for :func:`wait`. Note that POSIX does not specify the meaning 1845 of the return value of the C :c func:`system` function, so the return value of2157 of the return value of the C :c:func:`system` function, so the return value of 1846 2158 the Python function is system-dependent. 1847 2159 … … 1853 2165 documentation. 1854 2166 1855 Availability: Unix, Windows.1856 1857 2167 The :mod:`subprocess` module provides more powerful facilities for spawning new 1858 2168 processes and retrieving their results; using that module is preferable to using 1859 this function. Use the :mod:`subprocess` module. Check especially the 1860 :ref:`subprocess-replacements` section. 2169 this function. See the 2170 :ref:`subprocess-replacements` section in the :mod:`subprocess` documentation 2171 for some helpful recipes. 2172 2173 Availability: Unix, Windows. 1861 2174 1862 2175 1863 2176 .. function:: times() 1864 2177 1865 Return a 5-tuple of floating point numbers indicating accumulated (processor or 1866 other) times, in seconds. The items are: user time, system time, children's 1867 user time, children's system time, and elapsed real time since a fixed point in 1868 the past, in that order. See the Unix manual page :manpage:`times(2)` or the 1869 corresponding Windows Platform API documentation. Availability: Unix, 1870 Windows. On Windows, only the first two items are filled, the others are zero. 2178 Return a 5-tuple of floating point numbers indicating accumulated (processor 2179 or other) times, in seconds. The items are: user time, system time, 2180 children's user time, children's system time, and elapsed real time since a 2181 fixed point in the past, in that order. See the Unix manual page 2182 :manpage:`times(2)` or the corresponding Windows Platform API documentation. 2183 On Windows, only the first two items are filled, the others are zero. 2184 2185 Availability: Unix, Windows 1871 2186 1872 2187 … … 1877 2192 that killed the process, and whose high byte is the exit status (if the signal 1878 2193 number is zero); the high bit of the low byte is set if a core file was 1879 produced. Availability: Unix. 2194 produced. 2195 2196 Availability: Unix. 1880 2197 1881 2198 … … 1904 2221 equal to ``0`` has no special meaning on Windows, and raises an exception. The 1905 2222 value of integer *options* has no effect. *pid* can refer to any process whose 1906 id is known, not necessarily a child process. The :func:`spawn ` functions called1907 with :const:`P_NOWAIT` return suitable process handles.1908 1909 1910 .. function:: wait3( [options])2223 id is known, not necessarily a child process. The :func:`spawn\* <spawnl>` 2224 functions called with :const:`P_NOWAIT` return suitable process handles. 2225 2226 2227 .. function:: wait3(options) 1911 2228 1912 2229 Similar to :func:`waitpid`, except no process id argument is given and a 1913 2230 3-element tuple containing the child's process id, exit status indication, and 1914 2231 resource usage information is returned. Refer to :mod:`resource`.\ 1915 :func:`getrusage` for details on resource usage information. The option 1916 argument is the same as that provided to :func:`waitpid` and :func:`wait4`. 2232 :func:`~resource.getrusage` for details on resource usage information. The 2233 option argument is the same as that provided to :func:`waitpid` and 2234 :func:`wait4`. 2235 1917 2236 Availability: Unix. 1918 2237 … … 1924 2243 Similar to :func:`waitpid`, except a 3-element tuple, containing the child's 1925 2244 process id, exit status indication, and resource usage information is returned. 1926 Refer to :mod:`resource`.\ :func:`getrusage` for details on resource usage 1927 information. The arguments to :func:`wait4` are the same as those provided to 1928 :func:`waitpid`. Availability: Unix. 2245 Refer to :mod:`resource`.\ :func:`~resource.getrusage` for details on 2246 resource usage information. The arguments to :func:`wait4` are the same as 2247 those provided to :func:`waitpid`. 2248 2249 Availability: Unix. 1929 2250 1930 2251 .. versionadded:: 2.5 … … 1935 2256 The option for :func:`waitpid` to return immediately if no child process status 1936 2257 is available immediately. The function returns ``(0, 0)`` in this case. 2258 1937 2259 Availability: Unix. 1938 2260 … … 1941 2263 1942 2264 This option causes child processes to be reported if they have been continued 1943 from a job control stop since their status was last reported. Availability: Some 1944 Unix systems. 2265 from a job control stop since their status was last reported. 2266 2267 Availability: Some Unix systems. 1945 2268 1946 2269 .. versionadded:: 2.3 … … 1950 2273 1951 2274 This option causes child processes to be reported if they have been stopped but 1952 their current state has not been reported since they were stopped. Availability: 1953 Unix. 2275 their current state has not been reported since they were stopped. 2276 2277 Availability: Unix. 1954 2278 1955 2279 .. versionadded:: 2.3 … … 1963 2287 1964 2288 Return ``True`` if a core dump was generated for the process, otherwise 1965 return ``False``. Availability: Unix. 2289 return ``False``. 2290 2291 Availability: Unix. 1966 2292 1967 2293 .. versionadded:: 2.3 … … 1971 2297 1972 2298 Return ``True`` if the process has been continued from a job control stop, 1973 otherwise return ``False``. Availability: Unix. 2299 otherwise return ``False``. 2300 2301 Availability: Unix. 1974 2302 1975 2303 .. versionadded:: 2.3 … … 1979 2307 1980 2308 Return ``True`` if the process has been stopped, otherwise return 1981 ``False``. Availability: Unix. 2309 ``False``. 2310 2311 Availability: Unix. 1982 2312 1983 2313 … … 1985 2315 1986 2316 Return ``True`` if the process exited due to a signal, otherwise return 1987 ``False``. Availability: Unix. 2317 ``False``. 2318 2319 Availability: Unix. 1988 2320 1989 2321 … … 1991 2323 1992 2324 Return ``True`` if the process exited using the :manpage:`exit(2)` system call, 1993 otherwise return ``False``. Availability: Unix. 2325 otherwise return ``False``. 2326 2327 Availability: Unix. 1994 2328 1995 2329 … … 1998 2332 If ``WIFEXITED(status)`` is true, return the integer parameter to the 1999 2333 :manpage:`exit(2)` system call. Otherwise, the return value is meaningless. 2334 2000 2335 Availability: Unix. 2001 2336 … … 2003 2338 .. function:: WSTOPSIG(status) 2004 2339 2005 Return the signal which caused the process to stop. Availability: Unix. 2340 Return the signal which caused the process to stop. 2341 2342 Availability: Unix. 2006 2343 2007 2344 2008 2345 .. function:: WTERMSIG(status) 2009 2346 2010 Return the signal which caused the process to exit. Availability: Unix. 2347 Return the signal which caused the process to exit. 2348 2349 Availability: Unix. 2011 2350 2012 2351 … … 2025 2364 The names known to the host operating system are given as the keys of the 2026 2365 ``confstr_names`` dictionary. For configuration variables not included in that 2027 mapping, passing an integer for *name* is also accepted. Availability: 2028 Unix. 2366 mapping, passing an integer for *name* is also accepted. 2029 2367 2030 2368 If the configuration value specified by *name* isn't defined, ``None`` is … … 2036 2374 :const:`errno.EINVAL` for the error number. 2037 2375 2376 Availability: Unix 2377 2038 2378 2039 2379 .. data:: confstr_names … … 2041 2381 Dictionary mapping names accepted by :func:`confstr` to the integer values 2042 2382 defined for those names by the host operating system. This can be used to 2043 determine the set of names known to the system. Availability: Unix. 2383 determine the set of names known to the system. 2384 2385 Availability: Unix. 2044 2386 2045 2387 … … 2048 2390 Return the number of processes in the system run queue averaged over the last 2049 2391 1, 5, and 15 minutes or raises :exc:`OSError` if the load average was 2050 unobtainable. Availability: Unix. 2392 unobtainable. 2393 2394 Availability: Unix. 2051 2395 2052 2396 .. versionadded:: 2.3 … … 2059 2403 the *name* parameter for :func:`confstr` apply here as well; the dictionary that 2060 2404 provides information on the known names is given by ``sysconf_names``. 2405 2061 2406 Availability: Unix. 2062 2407 … … 2066 2411 Dictionary mapping names accepted by :func:`sysconf` to the integer values 2067 2412 defined for those names by the host operating system. This can be used to 2068 determine the set of names known to the system. Availability: Unix. 2413 determine the set of names known to the system. 2414 2415 Availability: Unix. 2069 2416 2070 2417 The following data values are used to support path manipulation operations. These … … 2122 2469 .. data:: defpath 2123 2470 2124 The default search path used by :func:`exec\*p\*` and :func:`spawn\*p\*` if the 2125 environment doesn't have a ``'PATH'`` key. Also available via :mod:`os.path`. 2471 The default search path used by :func:`exec\*p\* <execl>` and 2472 :func:`spawn\*p\* <spawnl>` if the environment doesn't have a ``'PATH'`` 2473 key. Also available via :mod:`os.path`. 2126 2474 2127 2475 … … 2137 2485 .. data:: devnull 2138 2486 2139 The file path of the null device. For example: ``'/dev/null'`` for POSIX.2140 Also available via :mod:`os.path`.2487 The file path of the null device. For example: ``'/dev/null'`` for 2488 POSIX, ``'nul'`` for Windows. Also available via :mod:`os.path`. 2141 2489 2142 2490 .. versionadded:: 2.4 … … 2156 2504 returned data should be unpredictable enough for cryptographic applications, 2157 2505 though its exact quality depends on the OS implementation. On a UNIX-like 2158 system this will query /dev/urandom, and on Windows it will use CryptGenRandom. 2159 If a randomness source is not found, :exc:`NotImplementedError` will be raised. 2506 system this will query ``/dev/urandom``, and on Windows it will use 2507 ``CryptGenRandom()``. If a randomness source is not found, 2508 :exc:`NotImplementedError` will be raised. 2509 2510 For an easy-to-use interface to the random number generator 2511 provided by your platform, please see :class:`random.SystemRandom`. 2160 2512 2161 2513 .. versionadded:: 2.4 2162
Note:
See TracChangeset
for help on using the changeset viewer.