I am trying to write something in a file by a daemon thread. The problem is that the file is being created but it is empty. Is it possible to write in a file by a daemon thread?
The reason of using daemon thread is because my main program will terminate first as compared to my thread. So in order to keep that thread running even after the execution of the program daemon is used.
Below is the code:
import threading
def hlp():
with open("/path/to/y.txt",mode="w") as f:
f.write("Hello")
def test():
thr=threading.Thread(target=hlp)
thr.daemon=True
thr.start()
test()