Python randomly exits with Linux OS error -9 or -15

Adam Skutt askutt at gmail.com
Mon Apr 9 09:34:37 EDT 2012


On Apr 9, 6:01 am, Janis <janis.vik... at gmail.com> wrote:
> Hello!
>
> I have this problem with my script exiting randomly with Linux OS
> status code -9 (most often) or -15 (also sometimes, but much more
> rarely). As far as I understand -9 corresponds to Bad file descriptor
> and -15 Block device required.
>

As Alain already said, you're probably hitting a resource limit of
some sort or another and your program is being forcibly terminated as
a result.  You may just need to increase ulimits or system-wide
limits, or you may have a resource leak.  There may be output in the
kernel logs (dmesg) or some /var/log file if this is the case.

> 1) Is there a way how I could find out what exactly causes Python
> process to exit?

Use a debugger or at least turn on core dumps, so you have something
to examine after the crash.  Tracking through the output to figure out
where you crashed in the Python code is difficult, but possible.

> I have a try-catch block in the root of the script which works very
> well to catch any kind of exceptions, but in these cases either Python
> does not catch the exception or fails to log it into MySQL error log
> table.

You need to fix your handler to log the exception to stderr or
similiar, as it will make fixing your application much easier.  It's
virtually impossible for anyone to help you if you don't know exactly
what's going on.

It's also highly likely that your current handler is throwing an
exception while running and masking the original error.  I would
seriously advise taking it out, at least temporarily.  This is why
catch-all handlers tend to be a poor idea, as they're rarely robust in
the cases you didn't consider.

Adam



More information about the Python-list mailing list