Files
pythonkurs/teil12/multi_write.py
2023-03-28 12:26:50 +02:00

33 lines
608 B
Python

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()