How do I check if Telnet session is open?

Mudcat mnations at gmail.com
Tue Oct 19 17:53:30 EDT 2004


Hi all,

I am running a script that uses telnet sessions which have to remain
open for an extended period of time. The device under test I'm working
on times out the sessions after 10 mns for security reasons due to
inactivity, and there are long stretches of time where I am unable to
do any type of maintenance process where I can prod them to stay open.

In order to work around this I have created a class that has exceptions
where if the session is closed it will automatically re-open since it
retains it's ip/port info. I thought this would fix my problem, but it
didn't completely.

The problem comes because Python is unaware that the session has closed
when it tries to write to it. I don't know the internal workings of
telnet sessions or how it's supposed to work, but according the Python
the write is successful. However when the read occurs, then it fails. I
could put exception handling there also, but by then it's too late. The
write has already been lost.

So how can I from within Python tell if a session is still open before
writing to it? I don't see any options in Telnet class that do it. Is
there any way?

Thanks ahead of time,
Marc




More information about the Python-list mailing list