Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#47 File descriptor leaking

v1.0 (example)
closed
Chris Liechti
None
5
2013-10-11
2011-06-16
Anonymous
No

Hello,

Im using pyserial in a part of my project, I notice that the serial.close() method doesnt close properly the file causing file descriptor leaking, is that correct? How can I avoid that problem?

the executions of:
print s
s.close()
print s

Serial<id=0xb707b90c, open=True>(port='/dev/ttyUSB3', baudrate=230400, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)

Serial<id=0xb707b90c, open=False>(port='/dev/ttyUSB3', baudrate=230400, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)

But the file still open acording to lsof -p PID

And of course after awhile this error makes failure of all the other component of my project, cos I dont know how to flush that fd in order to create more

Thanks,

Discussion

  • Chris Liechti
    Chris Liechti
    2011-08-05

    • status: open --> pending
     
  • Chris Liechti
    Chris Liechti
    2011-08-05

    works for me (Python 2.6, pySerial 2.6 (SVN))

    i checked with lsof and the file descriptor appeared and disappeared.

     
  • Chris Liechti
    Chris Liechti
    2011-08-05

    • assigned_to: nobody --> cliechti
     
  • Ranen Ghosh
    Ranen Ghosh
    2013-06-23

    I experienced the same thing, but I realized that I was erroneously calling the open method on the Serial object after constructing it.

    The Serial object was already open upon construction, and calling the open method seemed to double the number of entries in lsof. Then calling the close method did not remove all of the entries, and later I couldn't write to the serial port.

    Maybe calling open on an already-open object should do nothing, or throw an exception, or something, rather than causing this problem.

     
  • Chris Liechti
    Chris Liechti
    2013-10-11

    An exception is now raised when trying to open the port a second time.

     
  • Chris Liechti
    Chris Liechti
    2013-10-11

    • status: pending --> closed
    • Group: --> v1.0 (example)