I am trying to create/open and write to a file from thread.
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()
The problem is that when I un-comment 2nd line (t.daemon = True) of the test function it stops working. Is there any way to make it work in the daemon thread mode ??
I can't find any solution on internet or even related to this. I know it is not the best way for file operation.