import threading import logging logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', filename='multi_write.log', level=logging.DEBUG) datei = open('zahlen.txt','w') def write_number(zahl): for i in range(0,1000): logging.debug(f'Thread {zahl}/schreibe {i}') datei.write(f'{i}:{zahl}\n') datei.flush() thread_1 = threading.Thread(target=write_number,args=(1,)) thread_2 = threading.Thread(target=write_number,args=(2,)) logging.debug('starte Thread 1') thread_1.start() logging.debug('starte Thread 2') thread_2.start() thread_1.join() thread_2.join()