0
votes

I want to control my processes while I not found working url.

But I have NameError: name 'status' is not defined due to threads not waiting to declare a variable

import requests
from multiprocessing import Process


def first_function(i):
    global status
    status = False
    try:
        response = requests.get(f'https://ru.hexlet.io/{i}')
        if response.status_code == 200:
            status = True
    except Exception as e:
        print(str(e))


def second_function():
    for i in [1,2,3,4,5,6,'courses',8,9,10]:
        Process(target=first_function, args=(i, )).start()
        print(i)
        if status:
            print('working', i)
            break


if __name__ == '__main__':
    second_function()