How to solve this error? i want to pass the values from get_robotxya() and get_ballxya()
and use it in a loop but it seems that it will crash after awhile how do i fix this? i want to get the values whithout it crashing out of the while loop
import socket
import os,sys
import time
from threading import Thread
HOST = '59.191.193.59'
PORT = 5555
COORDINATES = []
def connect():
globals()['client_socket'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST,PORT))
def update_coordinates():
connect()
screen_width = 0
screen_height = 0
while True:
try:
client_socket.send("loc\n")
data = client_socket.recv(8192)
except:
connect();
continue;
globals()['COORDINATES'] = data.split()
if(not(COORDINATES[-1] == "eom" and COORDINATES[0] == "start")):
continue
if (screen_width != int(COORDINATES[2])):
screen_width = int(COORDINATES[2])
screen_height = int(COORDINATES[3])
return
def get_ballxy():
update_coordinates()
ballx = int(COORDINATES[8])
bally = int(COORDINATES[9])
return ballx,bally
def get_robotxya():
update_coordinates()
robotx = int(COORDINATES[12])
roboty = int(COORDINATES[13])
angle = int(COORDINATES[14])
return robotx,roboty,angle
def print_ballxy(bx,by):
print bx
print by
def print_robotxya(rx,ry,a):
print rx
print ry
print a
def activate():
bx,by = get_ballxy()
rx,ry,a = get_robotxya()
print_ballxy(bx,by)
print_robotxya(rx,ry,a)
Thread(target=update_coordinates).start()
while True:
activate()
this is the error i get: