trying to read from dying disk

Mike Meyer mwm at mired.org
Fri Apr 22 18:51:38 EDT 2005


jdh2358 at gmail.com writes:

> I have a python file that is trying to read raw data from a raw
> partition on a dying dist, eg
>
>   f = file('/dev/sda')
>   f.seek(SOMEWHERE)
>   s = f.read(SOMEBYTES)
>
> On some blocks, the read succeeds, on others it fails and an IOError is
> thrown, and on others it appears to hang indefinitely and will not
> respond to any attempt to kill it with 'kill -9 PID', etc.
>
> Is there anyway to do a timeout read on this kind of file, or even to
> kill the process once it hangs?
>
> linux kernel 2.6.10
> python 2.4.1

Don't do this in Python. Dealing with flaky hardware is a maintenance
problem, and applications should report the error, and either exit or
proceed as best as possible after the error.

Use the "dd" command to extract as much good data as you can from the
failing disk.

Ok, if you *really* want to do this in Python, the answer is - you
need to provide more information. For instance, *where* does the
process hang? It's possible you've hung the process in an
uninterruptible state in the kernel. If so, you're screwed. You need
to find out where the process hangs (kernel, libc, python, etc.), and
if in the kernel what it's waiting on. In the latter case, you need to
ask on a Linux list.

    <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list