是否可以从线程函数返回变量?

时间:2019-03-16 16:58:36

标签: python multithreading function variables return

我想从某个线程返回true或false,我的代码是:

def main(chat_id):
  # use a different driver for each thread
  chrome_options = Options()
  sleep(0.5)
  chrome_options.add_argument('user-data-dir=/home/ale/botTelegram/users/' + chat_id + '/cookies')
  # chrome_options.add_argument('--headless')
  chrome_options.add_argument('--no-sandbox')
  chrome_options.add_argument('--lang=en')
  print("Starting WebDrivers")
  browser = webdriver.Chrome(options=chrome_options)
  sleep(2)
  user = igLogin.checkAlreadyLoggedIn(browser, chat_id)
  print(user, chat_id) #this print in the console True or False + chat_id

  return user


def start_thread_browser(chat_id):
    user = threading.Thread(target=main(chat_id)).start()
    print(user, chat_id) #this print in the console None + chat_id

如何从线程中对对或错进行控制?安全吗?如果我将其存储在数据库中会更好吗?

0 个答案:

没有答案