[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-18 Thread R. David Murray

R. David Murray  added the comment:

IMO it is better to have an API that can be used when, for example, writing 
tests, than to monkey patch.  On the other hand, I've never had an occasion 
when I cared about the names of tempfiles (or directories) in my test code, and 
it is hard to imagine a circumstance when being able to reproduce the sequence 
of tempfile names chosen would matter for debugging...especially since which 
filenames are actually chosen from the randomly generated sequence can depend 
on other activity on the system.  So I concur with the rejection. 

I wouldn't object to some sort of API that allowed one to control the filename 
generation without worrying that later changes to the module would break ones 
code, but that isn't actually the use case here, so no one has actually asked 
for this feature ;)

--
nosy: +r.david.murray
resolution: fixed -> rejected

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-16 Thread Julien Palard

Julien Palard  added the comment:

I concur with Raymond and Serhiy here, and monkeypatching tmpfile should not be 
that hard, maybe patching `tempfile._Random` with `partial(random.Random, 
seed)` if done soon enough?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-16 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

I concur with Raymond.

Monkey patching the tempfile module looks the right solution of this uncommon 
problem.

--
nosy: +serhiy.storchaka
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-15 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

This seems ill-advised:

* If a deterministic filename is needed, tempfile probably shouldn't be used.

* Mock objects are typically used when alternative behavior is needed for 
testing.

* The proposed feature would preclude a possible future development path to use 
SystemRandom which wouldn't be able to accept a seed.

* Having the same filename used on successive runs will likely cause other 
problems. Generally, a user of tempname can assume that filename doesn't 
already exist and the proposed option would undermine that assumption.

* I suspect if there were a real need here, we would have heard about it a long 
time ago.  This module is over two decades old.

--
components: +Library (Lib)
versions: +Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-12 Thread Yaroslav Halchenko

Yaroslav Halchenko  added the comment:

I have spent too much time in Python to be able to compare to other languages 
;)  but anywhere I saw RNG being used, there was a way to seed it or to provide 
a state.  tempfile provides no such API

my usecase -- comparison of logs from two runs where I need to troubleshoot the 
point of divergence in execution .  Logs in our case (datalad) contain 
temporary directory filenames, so they always "diff" and I need to sift through 
them or to come up with some obscure sed regex to unify them.  I found in other 
projects of ours a really handy to be able to seed RNG globally so two runs 
result in identical execution path -- allows for easier 
reproducibility/comparison.  But when it got to those temporary filenames -- 
apparently I could not make it happen and would need to resort to some heavy 
monkey patching.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-12 Thread Julien Palard

Julien Palard  added the comment:

Or is there any issue that would have been easier to fix with reproductible 
temporary file names?

--
nosy: +mdk

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-12 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

I'm suspect this not would be wise thing to do.  Have you seen any precedent 
for this in other languages?

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32276] there is no way to make tempfile reproducible (i.e. seed the used RNG)

2017-12-11 Thread Yaroslav Halchenko

New submission from Yaroslav Halchenko :

It is quite often desired to reproduce the same failure identically. In many 
cases sufficient to seed the shared random._inst (via random.seed). tempfile 
creates new instance(s) for its own operation and does not provide API to seed 
it.  I do not think it would be easy (unless I miss some pattern) to make it 
deterministic/reproducible for multi-process apps, but I wondered why initially 
(for the main process) tempfile module doesn't just reuse the random._inst 
while only creating a new _Random in children processes?
Another alternative solution would be to allow to specify seed for all those 
mkstemp/mkdtemp/... and pass it all way to _RandomNameSequence which would 
initialize _Random with it.  This way, developers who need to seed it, could do 
so

--
messages: 308043
nosy: Yaroslav.Halchenko
priority: normal
severity: normal
status: open
title: there is no way to make tempfile reproducible (i.e. seed the used RNG)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com