Python 也许能帮上忙?
所以我需要让这两个东西同时运行Python 也许能帮上忙?,python,multithreading,matplotlib,Python,Multithreading,Matplotlib,所以我需要让这两个东西同时运行 savedFile = open('Exchange_Rates' + time.strftime("_%d.%m.%Y.log"), 'w') while spot < 60: savedFile.write(str(currencies.get_rate()) + ',' + str(spot) + '\n') savedFile.flush() spot += 1 time.sleep(1) savedFile.
savedFile = open('Exchange_Rates' + time.strftime("_%d.%m.%Y.log"), 'w')
while spot < 60:
savedFile.write(str(currencies.get_rate()) + ',' + str(spot) + '\n')
savedFile.flush()
spot += 1
time.sleep(1)
savedFile.close()
我是否需要使用线程模块,或者如何使用它。或者我是否使用了其他工具,如果是,又是什么?是的,我认为您需要线程模块。我会推荐你这篇文章 最简单的方法是:
import thread
def someFunc():
print "someFunc was called"
thread.start_new_thread(someFunc, ())
更先进的方法是:
import threading
t1 = threading.Thread(target=someFunc)
t1.start()
t1.join()
import threading
t1 = threading.Thread(target=someFunc)
t1.start()
t1.join()