Message159046
| Author |
neologix |
| Recipients |
neologix, phlogistonjohn, vinay.sajip |
| Date |
2012年04月23日.17:05:35 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<CAH_1eM03ksEPJFn6TiCGb6La4p1AFiBV7mCgvDy7vCRSz=3C6A@mail.gmail.com> |
| In-reply-to |
<1335122190.86.0.99243390963.issue14632@psf.upfronthosting.co.za> |
| Content |
> Charles-François: Certainly I can reduce the iterations to make the test
> faster. As it is, I did reproduce the failure on my dev system, but only
> once, after running John's test script about a dozen times: every other
> time, it completed successfully :-(
Juste reduce the sleep times, e.g.:
"""
@@ -17,7 +17,7 @@
os.unlink(fname)
except OSError:
pass
- stime = 0.04 * random.randint(0, 4)
+ stime = 0.004 * random.randint(0, 4)
time.sleep(stime)
@@ -50,7 +50,7 @@
log.setLevel(logging.INFO)
for ii in range(LOGCOUNT):
- stime = 0.05 # * random.randint(0, 4)
+ stime = 0.005 # * random.randint(0, 4)
time.sleep(stime)
log.warning('Foo bar %d', ii)
"""
With this change, I can trigger a failure reliably in around 1s, and
my computer is rather slow.
> Isn't it simpler if I just replace the os.path.exists() calls with
> os.stat(), and check for ENOENT if an exception of type OSError or
> WindowsError occurs?
The problem is that it would leave a race window if the file is
changed between the time it's opened (I guess in
logging.FileHandler.__init__()) and the first call to stat().
John's patch is safe in this regard, thanks to fstat(). |
|