我试图比较许多处理器和许多编程语言的速度,但我在python中的多线程问题:
def main(argv):
start_time = time.time()
case_number = 2
nb_thread = 2
t = [0] * nb_thread
for i in range(0, nb_thread):
t[i] = Thread(target=resolve, args=("TREAD " + str(i),)) // resolve is a mathematic problem (about 6 seconds to resolve it)
t[i].start()
t[0].join()
t[1].join()
print("--- %s seconds ---" % (time.time() - start_time))
if __name__ == '__main__':
main(sys.argv)
具有1个线程和1个resolve((=>6秒并且具有2个线程和2个resolve((=>12秒
使用resolve((中的print((,你在这里看不到,我读到:
D:DevpythonSudoku>python main.py txt.txt
TREAD 0 <<BEGUIN>>
TREAD 1 <<BEGUIN>>
TREAD 0 <<END>>
TREAD 1 <<END>>
--- 12.335727453231812 seconds ---
我似乎有什么不明白的地方:/非常感谢。
realpython.com/python-gil
很有趣,谢谢!