annotate Doc/libtempfile.tex @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents f47bc5554418
children 3468ea8645ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2576
f47bc5554418 mass changes; fix titles; add examples; correct typos; clarifications;
Guido van Rossum <guido@python.org>
parents: 2527
diff changeset
1 \section{Standard Module \sectcode{tempfile}}
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 \stmodindex{tempfile}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \indexii{temporary}{file name}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 \indexii{temporary}{file}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 \renewcommand{\indexsubitem}{(in module tempfile)}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
8 This module generates temporary file names. It is not \UNIX{} specific,
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
9 but it may require some help on non-\UNIX{} systems.
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 Note: the modules does not create temporary files, nor does it
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 automatically remove them when the current process exits or dies.
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 The module defines a single user-callable function:
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 \begin{funcdesc}{mktemp}{}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 Return a unique temporary filename. This is an absolute pathname of a
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 file that does not exist at the time the call is made. No two calls
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 will return the same filename.
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 \end{funcdesc}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 The module uses two global variables that tell it how to construct a
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 temporary name. The caller may assign values to them; by default they
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 are initialized at the first call to \code{mktemp()}.
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 \begin{datadesc}{tempdir}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 When set to a value other than \code{None}, this variable defines the
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 directory in which filenames returned by \code{mktemp()} reside. The
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 default is taken from the environment variable \code{TMPDIR}; if this
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
30 is not set, either \code{/usr/tmp} is used (on \UNIX{}), or the current
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 working directory (all other systems). No check is made to see
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 whether its value is valid.
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 \end{datadesc}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 \ttindex{TMPDIR}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \begin{datadesc}{template}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 When set to a value other than \code{None}, this variable defines the
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 prefix of the final component of the filenames returned by
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 \code{mktemp()}. A string of decimal digits is added to generate
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 unique filenames. The default is either ``\code{@\var{pid}.}'' where
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
41 \var{pid} is the current process ID (on \UNIX{}), or ``\code{tmp}'' (all
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 other systems).
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 \end{datadesc}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
2527
815dfaa6a778 small changes by Soren Larsen
Guido van Rossum <guido@python.org>
parents: 2460
diff changeset
45 Warning: if a \UNIX{} process uses \code{mktemp()}, then calls
2460
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 \code{fork()} and both parent and child continue to use
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 \code{mktemp()}, the processes will generate conflicting temporary
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 names. To resolve this, the child process should assign \code{None}
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 to \code{template}, to force recomputing the default on the next call
1c29f6bdd898 en weer twee!
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 to \code{mktemp()}.