I'm building system which haves a lot of processes running aside and one is - Getting user IP. For that I use Thread and I need to get variable back. The result is always None when outside the function, but in the loop it keeps printing my IP address. As a result my output is:
None
Your ip is : 85.206.**.*
My Code:
IPadress = None
def Get_IP():
while True:
try:
data = urlopen(Ip_Url).read()
adressas = data.decode('UTF-8')
global IPadress
IPadress = adressas
print("Your ip is : ", IPadress)
except Exception as erroras:
print("Can't connect!", erroras)
time.sleep(5)
sys.exit()
time.sleep(5)
Thread(target = Get_IP).start()
print(IPadress)
How can I get the result from thread outside the function?