<s>[INST] import os
import sys
import time
import threading
import Queue

def create_file():
    with open('test.txt', 'a') as f:
        for i in range(1000):
            f.write('Hello, World!\n')

def read_file():
    with open('test.txt', 'r') as f:
        for line in f:
            print(line, end='')

def main():
    t1 = threading.Thread(target=create_file)
    t2 = threading.Thread(target=read_file)
    t1.start()
    t2.start()

if __name__ == '__main__':
    main()

This program will sometimes throw the following exception when run:

Exception in thread Thread-2:
RuntimeError: can't seek a closed file object
What is happening here, and how can you solve this problem?[/INST]