Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 也许能帮上忙?_Python_Multithreading_Matplotlib - Fatal编程技术网

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()