[Python-Dev] Segfault

Hrvoje Nikšić hrvoje.niksic at avl.com
Wed Aug 22 10:35:18 CEST 2007


On Tue, 2007-08-21 at 09:14 -0700, Neal Norwitz wrote:
> The patch is insufficient to prevent all types of crashes that occur
> when accessing a file from 2 threads (closing in one and doing
> whatever in another).

You are right.  I wouldn't go so far to say the file object
thread-unsafe, but it certainly has lurking bugs with calling close
while other threads are running.  BTW your mail doesn't seem to contain
the actual patch.

> Almost every place that accesses f_fp is a problem.

I think we need a reliable mechanism to prevent file_close messing with
f_fp while other operations are being performed.  Since each FILE has an
internal lock associated with it, flockfile could be used to lock out
the sections that access f_fp (falling back to a mutex in PyFileObject
on platforms without flockfile) without affecting other threads that
operate on other FILE's.

It's questionnable whether such an overhaul would pay off, given the
Py3k rewrite of the IO subsystem.




More information about the Python-Dev mailing list