Message11357

Author jeff.allen
Recipients jeff.allen
Date 2017-05-06.15:00:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494082819.39.0.699323975812.issue2588@psf.upfronthosting.co.za>
In-reply-to
Content
A couple of tests in test_io have started failing for me. This is the case since I localised my PC to Chinese, but encoding seems to have nothing to do with the failure.

The test opens one file and creates 20 threads that compete to write in it. There is no explicit synchronisation. The test fails if, at the end, the file does not contain exactly one message from each thread. Comments reference: http://bugs.python.org/issue6750 . Obviously, this is asking for trouble ;)

If I reduce the number of threads below about 10 it passes, so maybe it only ever passed because something was faster, slower or "stickier" than now, effectively serialising access.

The problem arises in CPython because writing releases the GIL in the middle of managing the buffered data. CPython's solution relies on dancing around the moment when the GIL is given up. In the tracker, this appears to be the triumph of pragmatism over purism. The first answer was that it was "not designed to be thread-safe at all".

Of course, we don't have a GIL in Jython, hence I'm actually wondering how this test ever passed, and whether we should expect it to. I'm going to insert a skip for now, referring to this issue.

I'm seeing this in the trunk repository (alongside the errors that *are* to do with encoding):

======================================================================
FAIL: test_threads_write (__main__.CTextIOWrapperTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Jeff\Documents\Eclipse\jython-trunk\dist\Lib\test\test_io.py", line 2460, in test_threads_write
    self.assertEqual(content.count("Thread%03d\n" % n), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_threads_write (__main__.PyTextIOWrapperTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\Jeff\Documents\Eclipse\jython-trunk\dist\Lib\test\test_io.py", line 2460, in test_threads_write
    self.assertEqual(content.count("Thread%03d\n" % n), 1)
AssertionError: 0 != 1

----------------------------------------------------------------------

In my fork, when I've dealt with the encoding problems, I still have these threading failures.
History
Date User Action Args
2017-05-06 15:00:19jeff.allensetrecipients: + jeff.allen
2017-05-06 15:00:19jeff.allensetmessageid: <1494082819.39.0.699323975812.issue2588@psf.upfronthosting.co.za>
2017-05-06 15:00:19jeff.allenlinkissue2588 messages
2017-05-06 15:00:17jeff.allencreate