Forgot to close a device file ... what now?

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Sat Sep 15 23:19:05 EDT 2001


----- Original Message ----- 
From: "Jyrinx" <jyrinx_list at hotmail.com>


> Hey - Python newbie here. I'm running Python on Red Hat Linux 7.1. At
> the interpreter prompt, I ran "fd = open("/dev/ttyS0", "wb")", then
> went off to do something else, came back, forgot to close the file,
> then quit Python. Next time I ran the interpreter, I tried to open the
> serial port again, but I got an error saying the file is locked or
> busy.
> 
> What can I do to reopen it, short of resetting the system?

When the main Python interpreter exits, all open file descriptors are
closed.  (Actually this is true of any Linux process).  This means that
either the Python interpreter is still running, or your Linux system has
a bug.

First, do 

    ps -ax | grep python

and look for the interpreter running.  If you find it (and are sure it's
not some other Python script), kill it.

Failing this, shut down and restart; this might indicate a kernel bug of
some sort.








More information about the Python-list mailing list