trying to read from dying disk

Discussion in 'Python' started by jdh2358@gmail.com, Apr 22, 2005.

  1. Guest

    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

    Thanks!
    JDH
    , Apr 22, 2005
    #1
    1. Advertising

  2. John J. Lee Guest

    writes:

    > I have a python file that is trying to read raw data from a raw
    > partition on a dying dist, eg

    [...]
    > 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


    This sounds like a linux kernel question much more than a Python one.
    Try a linux programmers' list?


    John
    John J. Lee, Apr 22, 2005
    #2
    1. Advertising

  3. Guest

    > This sounds like a linux kernel question much more than a Python
    > one. Try a linux programmers' list?


    Except that I'm writing a *python* program and trying to do a timeout
    on the python *file* read operation. If I asked the question on the
    kernel mailing list, they would rightlyfully assume I suspect that I
    should be writing a C program, and then they would suggest c.l.py.

    I'm currently attempting something with

    http://www.python.org/doc/current/lib/node368.html

    but it seems the read operation is ignoring these signals just as it is
    ignoring my signals from the kill command -- perhaps unsurprisingly.

    Perhaps there is no hope.
    JDH
    , Apr 22, 2005
    #3
  4. wrote:

    > Except that I'm writing a *python* program and trying to do a timeout
    > on the python *file* read operation.


    and that *python* program is using the *C* runtime library, which calls
    the *kernel* to do the work.

    > If I asked the question on the kernel mailing list, they would rightly-
    > fully assume I suspect that I should be writing a C program, and then
    > they would suggest c.l.py.


    if you asked the question in an intelligent way, they would probably explain
    what mechanisms the kernel provides for this purpose, and give you the
    hints you need to solve this. in general, Python and C has no control what-
    soever over what the operating system kernel does when reading data from
    a disk. surely you know that?

    </F>
    Fredrik Lundh, Apr 22, 2005
    #4
  5. Mike Meyer Guest

    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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, Apr 22, 2005
    #5
  6. Hi All--

    wrote:
    >
    > I'm currently attempting something with
    >
    > http://www.python.org/doc/current/lib/node368.html
    >
    > but it seems the read operation is ignoring these signals just as it is
    > ignoring my signals from the kill command -- perhaps unsurprisingly.
    >
    > Perhaps there is no hope.
    >



    Basically, if you are waiting for a hardware interrupt that never comes,
    you are doomed. You can escape by rebooting; in dire cases the only way
    out is to power down. One of the prime sources of zombie processes on
    unix systems is users trying to interrupt (with ^C) a process that is
    waiting for a hardware interrupt.

    Metta,
    Ivan
    ----------------------------------------------
    Ivan Van Laningham
    God N Locomotive Works
    http://www.andi-holmes.com/
    http://www.foretec.com/python/workshops/1998-11/proceedings.html
    Army Signal Corps: Cu Chi, Class of '70
    Author: Teach Yourself Python in 24 Hours
    Ivan Van Laningham, Apr 23, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Letford

    session keeps dying?

    Steve Letford, Aug 5, 2003, in forum: ASP .Net
    Replies:
    8
    Views:
    424
  2. Jas Shultz
    Replies:
    0
    Views:
    946
    Jas Shultz
    Dec 3, 2003
  3. James Kimble
    Replies:
    36
    Views:
    1,101
    unbending
    Jan 26, 2005
  4. Replies:
    12
    Views:
    520
    santosh
    Nov 15, 2006
  5. ragtag99
    Replies:
    13
    Views:
    847
    Bill Todd
    Sep 22, 2006
Loading...

Share This Page