I just started learning threads in Python. Here is the task: The main program thread should generate random content lines and put them at the end of the list. Child stream # 1 should display the current state of the list on the screen. Child stream # 2 wakes up every five seconds and sorts the list in lexicographical order and saves it to a file. Everything works, except for writing to the file. Tell me, please, what's the problem?
import threading import time from random import choice from string import ascii_letters def sortirovka(): f = open("qw.txt", "w") while 4 > 0: time.sleep(5) spicok.sort(key=str.lower) f.write(str(spicok)) def printer(): f = open("qw.txt", "r") while 4 > 0: print(spicok) time.sleep(1) spicok = [] t = threading.Thread(target=sortirovka) p = threading.Thread(target=printer) t.start() p.start() while 4 > 0: spicok.append(''.join(choice(ascii_letters) for i in range(12))) time.sleep(1)