Teile 10 bis 12.
This commit is contained in:
32
teil12/multi_write.py
Normal file
32
teil12/multi_write.py
Normal 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()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user