多线程两个函数

Multithreading two functions

我有两个函数,一个叫 connect() 用于登录我的帐户,另一个叫 identify_2bgval() 从我的 account.Since 获取一些数据,这是一个很长的过程我尝试使用多线程。

我的问题是:我可以同时使用这两个功能吗? 我想创建一个新函数然后使用 Threads.Is 它会起作用吗?另外,我可以将双目标与 Thread() 函数一起使用吗?

run_together():
 connect()
 identify_2bgval()
Thread(target= run_together).start()

如果 identify_2bgval 不依赖于 connect 你可以 运行 它在不同的线程中

def run_together():
    t = Thread(target=identify_2bgval)
    t.start() #2nd thread
    connect() # main thread waits here ...
    t.join() # wait for the 2nd thread ...

#call it ...
run_together() #blocks until finished ...