Index: Lib/io.py =================================================================== --- Lib/io.py (révision 65930) +++ Lib/io.py (copie de travail) @@ -61,7 +61,7 @@ import _fileio # Import _thread instead of threading to reduce startup cost try: - from _thread import allocate_lock as Lock + from _thread import RLock as Lock except ImportError: from _dummy_thread import allocate_lock as Lock Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (révision 65930) +++ Lib/test/test_io.py (copie de travail) @@ -1237,6 +1237,20 @@ else: self.assert_(issubclass(obj, io.IOBase)) + def testIssue3618(self): + # deadlock in BufferedRandom.write() when using an hook in ceval + # (eg. using a profiler) + import _lsprof + stream = io.BufferedWriter(io.StringIO()) + def invalidTimestamp(): + stream.write(b"in the profiler\n") + return 1 + profiler = _lsprof.Profiler(invalidTimestamp) + try: + profiler.enable() + stream.write(b"test deadlock\n") + finally: + profiler.disable() def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest,