tempfile bug or doc bug 
Author Message
 tempfile bug or doc bug

the docs to tempfile state that:

Warning: if a Unix process uses mktemp(), then calls fork() and both
parent and child continue to use mktemp(), the processes will generate
conflicting temporary names.  To resolve this, the child process
should assign None to template, to force recomputing the default on
the next call to mktemp().

So I have a unix process (part of mailman) that forks, and can fork
quite a bit,  the parent process *never* calls mktemp, but the child
processes all do, and i have darn good evidence of generation of
duplicate file names by mktemp() under these circumstances.

i suggest that we either fix the docs to mktemp to include this
circumstance as an exception or make mktemp() not generate duplicates
under these circumstances.

scott



Sun, 01 Apr 2001 03:00:00 GMT  
 tempfile bug or doc bug
just read the tempfile.py source and saw the reason behind this:

tempfile.mktemp says

        while ...
            if not os.path.exists(filename):
                return filename

the app says

fname = tempfile.mktemp()
fp = open(fname, "a+")

which doesn't exactly test whether the path exists and simultaneously
create a file ;)

perhaps a better warning should be added to mktemp docs?

scott

|
| the docs to tempfile state that:
|
| Warning: if a Unix process uses mktemp(), then calls fork() and both
| parent and child continue to use mktemp(), the processes will generate
| conflicting temporary names.  To resolve this, the child process
| should assign None to template, to force recomputing the default on
| the next call to mktemp().
|
| So I have a unix process (part of mailman) that forks, and can fork
| quite a bit,  the parent process *never* calls mktemp, but the child
| processes all do, and i have darn good evidence of generation of
| duplicate file names by mktemp() under these circumstances.
|
| i suggest that we either fix the docs to mktemp to include this
| circumstance as an exception or make mktemp() not generate duplicates
| under these circumstances.
|
| scott
|
|
|
|
|
|



Sun, 01 Apr 2001 03:00:00 GMT  
 tempfile bug or doc bug
Scott,

I propose the following patch to tempfile.py, which should take care
of your problems...

Index: tempfile.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/tempfile.py,v
retrieving revision 1.15
diff -c -r1.15 tempfile.py
*** tempfile.py 1998/04/28 16:03:34     1.15
--- tempfile.py 1998/10/14 13:56:04
***************
*** 60,70 ****

  # Function to calculate a prefix of the filename to use

  def gettempprefix():
!     global template
!     if template == None:
          if os.name == 'posix':

          elif os.name == 'nt':
              template = '~' + `os.getpid()` + '-'
          elif os.name == 'mac':
--- 60,76 ----

  # Function to calculate a prefix of the filename to use

+ _pid = None
+
  def gettempprefix():
!     global template, _pid
!     if os.name == 'posix' and _pid and _pid != os.getpid():
!         # Our pid changed; we must have forked -- zap the template
!         template = None
!     if template is None:
          if os.name == 'posix':
!             _pid = os.getpid()

          elif os.name == 'nt':
              template = '~' + `os.getpid()` + '-'
          elif os.name == 'mac':

--Guido van Rossum (home page: http://www.python.org/~guido/)



Sun, 01 Apr 2001 03:00:00 GMT  
 tempfile bug or doc bug
I think the patch is a good idea.

thx

scott

| Scott,
|
| I propose the following patch to tempfile.py, which should take care
| of your problems...
|
| Index: tempfile.py
| ===================================================================
| RCS file: /projects/cvsroot/python/dist/src/Lib/tempfile.py,v
| retrieving revision 1.15
| diff -c -r1.15 tempfile.py
| *** tempfile.py       1998/04/28 16:03:34     1.15
| --- tempfile.py       1998/10/14 13:56:04
| ***************
| *** 60,70 ****
|  
|   # Function to calculate a prefix of the filename to use
|  
|   def gettempprefix():
| !     global template
| !     if template == None:
|           if os.name == 'posix':

|           elif os.name == 'nt':
|               template = '~' + `os.getpid()` + '-'
|           elif os.name == 'mac':
| --- 60,76 ----
|  
|   # Function to calculate a prefix of the filename to use
|  
| + _pid = None
| +
|   def gettempprefix():
| !     global template, _pid
| !     if os.name == 'posix' and _pid and _pid != os.getpid():
| !         # Our pid changed; we must have forked -- zap the template
| !         template = None
| !     if template is None:
|           if os.name == 'posix':
| !             _pid = os.getpid()

|           elif os.name == 'nt':
|               template = '~' + `os.getpid()` + '-'
|           elif os.name == 'mac':
|
| --Guido van Rossum (home page: http://www.python.org/~guido/)



Sun, 01 Apr 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. BUGS, BUGS, BUGS, BUGS, C4 BUGS

2. PStore and tempfiles - bug?

3. Possible bug in Tempfile/Fork interaction

4. PopupMenu bug, menu bug, apple bug (worm)?

5. tempfile.mktemp no longer obeys tempfile.tempdir?

6. pydoc string.find (doc bug/typo?)

7. UDPServer bug or wrong doc?

8. Extension Doc bug

9. Fwd: gzip/zlib module Doc bug (1.5.2b2 Library Reference)

10. gzip/zlib module Doc bug (1.5.2b2 Library Reference)

11. Doc-string bug in exceptions.py

12. Doc bug ?

 

 
Powered by phpBB® Forum Software