This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients neologix, phlogistonjohn, vinay.sajip
Date 2012-04-23.20:02:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In-reply-to <>
>With this change, I can trigger a failure reliably in around 1s, and
>my computer is rather slow.

I'm working in a VM, and although I can get John's script to fail more regularly (with the reduced timeouts and counts of 1000), a version of the test which I added to test_logging always succeeds. That code is:

    @unittest.skipUnless(threading, 'Threading required for this test.')
    def test_race(self):
        # Issue #14632 refers.
        def remove_loop(fname, tries):
            for _ in range(tries):
                except OSError:
                time.sleep(0.004 * random.randint(0, 4))

        def cleanup(remover, fn, handler):
            if os.path.exists(fn):

        fd, fn = tempfile.mkstemp('.log', 'test_logging-3-')
        del_count = 1000
        log_count = 1000
        remover = threading.Thread(target=remove_loop, args=(fn, del_count))
        remover.daemon = True
        h = logging.handlers.WatchedFileHandler(fn)
        self.addCleanup(cleanup, remover, fn, h)
        f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
        for _ in range(log_count):
            r = logging.makeLogRecord({'msg': 'testing' })

I can't see why this always works, while John's script sometimes fails.
>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().

Oh, right - missed that.
Date User Action Args
2012-04-23 20:02:55vinay.sajipsetrecipients: + vinay.sajip, neologix, phlogistonjohn
2012-04-23 20:02:55vinay.sajiplinkissue14632 messages
2012-04-23 20:02:55vinay.sajipcreate