I want to write a program for my network course and i have a socket that listen to receive data if it listen and receive no data i should terminate the program, i use threading.Timer to act like timer and have a line like t = threading.Timer(5, end_data)
in my function that listen for receive data but i cant terminate program in end_data that is:
def end_data():
sys.exit()
can any one help me? i also test below code bud did not terminate running program in terminal :(
def end_data():
try:
sys.exit()
except:
print"exception"
i expect that when stop terminal print Tinas-MacBook-Pro:~ tina$
i'm listening to socket in function named receive not main and when elapse 5 second with no data receiving it will run end_data and seems never return to receive function that part of this function is like below
def receive():
s2 = socket(AF_INET, SOCK_DGRAM)
s2.bind(addr3_2)
global end_call
global base_window
write=open('pictur.jpg','wb')
s = socket(AF_INET, SOCK_DGRAM)
s.bind(addr3)
while(end_call==0):
t = threading.Timer(5, end_data)
t.start()
recv_data, addr = s.recvfrom(3500)#size ro hala badan check kon
t.cancel()
first i decide to set global var end_call after 5 second but it didn't work because it never come back to receive function
some thing that is very interesting for me is if define data_end like:
def end_data():
os._exit
print "Hi"
Hi will print in output :O