【发布时间】:2017-09-13 14:46:49
【问题描述】:
我正在尝试从线程创建/打开并写入文件。
from threading import Thread
CONNECTION_PORT = 9191
def testl():
file = open("testfile.txt","w")
file.write("Hello World")
file.write("This is our new text file")
file.write("and this is another line.")
file.write("Why? Because we can.")
file.close()
def test():
t = Thread(target=testl)
# t.daemon = True
t.start()
test()
问题是,当我取消注释测试函数的第二行 (t.daemon = True) 时,它停止工作。有没有办法让它在守护线程模式下工作??
我在互联网上找不到任何解决方案,甚至找不到与此相关的解决方案。我知道这不是文件操作的最佳方式。
【问题讨论】:
标签: python multithreading