如何实现“后台”或并发线程?

时间:2019-01-29 01:55:15

标签: python-3.x multithreading concurrent.futures

我想通了吗?运行正常。我无法查看原始代码,所以我写了这个新代码。有一个更好的方法吗?

import time
import threading

def threadee():
    f = open(r'log.txt')
    for line in f:
        print(line)
    time.sleep(0.2)

def threader():
    while True:
        threadee()
def main():
    thread = threading.Thread(target=threader)
    thread.start()
    while True:
        print('main thread running')
        print(threading.enumerate())
        time.sleep(1)

if __name__ == '__main__':
    main()

0 个答案:

没有答案