Python Forum
Running telnet loop freezes GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running telnet loop freezes GUI
#1
Hello there.

I am brand new to python and this is my first project.

Essentially I the script will allow a user to select a file from their computer that contains a list of IP's. The script will then take that list connect to each device on the list and monitor for a specific error. If the error is present then it will send a command to power cycle the device.

The issue is that when I select a file and it monitors for errors I loose all control on my GUI.

I was hoping to add more buttons, like a start and stop etc but I am stuck. Really not sure why the GUI locks up. I assume that it is waiting for my while loop to end. Is there a way to maintain control from the GUI while running a while loop.

Here is a copy of my code:

import telnetlib
import socket
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
import time


root = Tk()


def fileopen():
Tkinter.Tk().withdraw() # Close the root window
inpath = tkFileDialog.askopenfilename()
return inpath


def NoFault():
#tn.write("exit\n")
#print "session closed"
print "Time out"



def main():


#t = Timer(3.0, NoFault)
#t.start()

#read file
#file = open("hostnamelist.txt", "r")
#lines = file.readline(2)
#for line in lines:
#line = line.strip()

fp = open(fileopen()) # open file on read mode
lines = fp.read().split("\n") # create a list containing all lines
print lines

#IpAddr = lines
#for i in range(len(IpAddr)):
#print(IpAddr[i])

IpAddr = lines
i = 0
while i <= len(IpAddr):
print "Connecting to...",IpAddr[i]
#i = i + 1

sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if sck.connect_ex((IpAddr[i], 23)) == 0:
print "Connection established with ", IpAddr[i] ## Telnet is open do telnet related stuff here
#sck.close()


HOST = IpAddr[i]
tn = telnetlib.Telnet(HOST, "23")


tn.read_until("Welcome to the Tesira Text Protocol Server...")

tn.write("DEVICE get activeFaultList\r\n")

tn.write("exit\n")


TelnetOut = tn.read_all()

#print TelnetOut

print "Device checked at "

if TelnetOut.find("Unable to communicate with the IO card") == -1:
print "Specified Error not found"
print"_____________________________________________________________________"
else:
print "***Found error on device!***"
tn.open(HOST)
tn.read_until("Welcome to the Tesira Text Protocol Server...")
time.sleep(1)
tn.write("DEVICE recallPresetByName \"***Card slot error found device rebooted***\"\r\n")
time.sleep(3)
tn.write("DEVICE reboot\r\n")
tn.write("exit\n")

print "Device rebooted"
print"_____________________________________________________________________"

ActiveFaults = tn.write("DEVICE get activeFaultList\r\n")
DeviceSerial = tn.write("DEVICE get serialNumber\r\n")

else:
print"Could not connect to device at IP ", IpAddr[i]
print"_____________________________________________________________________"

i = i + 1


if i >= len(IpAddr):

print"*********************************************************************"
print"The following IP's have been checked"
print IpAddr
print"Completed "
print"*********************************************************************"



sck.close()
time.sleep(160)
i = 0





print len(IpAddr)
fp.close() # close file

print lines
file.close()

telnet = lines

menubar = Menu(root)

Start = Tkinter.Button(text ="Run Tesira Error Monitor", command = main)
Start.pack()

root.config(menu=menubar)
root.mainloop()

main()
Reply
#2
Hello, please post your code in Python code tags and possible errors (full traceback message) in error tags. You can find help here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,448 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  [PyQt] SSH port forwarding and connection to SQL Server in separate threads freezes jan_pips 25 10,435 Dec-03-2019, 04:28 PM
Last Post: Denni
  GUI freezes while executing a callback funtion when a button is pressed abi17124 5 7,388 Jul-10-2019, 12:48 AM
Last Post: FullOfHelp
  [Tkinter] tkinter freezes by clicking button Zatox11 33 25,309 Apr-10-2018, 09:03 AM
Last Post: Zatox11
  Clock freezes - wx.python glib problem strongheart 3 3,979 Oct-10-2017, 03:36 AM
Last Post: strongheart

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020