Teile 10 bis 12.

This commit is contained in:
2023-03-28 12:26:50 +02:00
parent 298151634d
commit f7a5db9f39
27 changed files with 6459 additions and 75 deletions

32
teil12/multi_write.py Normal file
View File

@@ -0,0 +1,32 @@
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()