Python/Logging/test_Logging_1129.py

64 lines
1.4 KiB
Python
Raw Normal View History

2024-04-19 19:24:34 +08:00
import threading
import multiprocessing as mp
from multiprocessing import Queue
#from queue import Queue #Thread 無法回傳值,所以要使用 Queue.put() 將要傳回的值存入 Queue再用 Queue.get() 取出
import time
import os
import datetime
import logging
import cv2
from Process_class import Process_class
from Thread_class import Thread_class
log_file = f'LOG.txt'
# create logger
logger = logging.getLogger(log_file)
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create file handler and set level to info
fh = logging.FileHandler(log_file)
fh.setLevel(logging.INFO)
# create formatter
formatter = logging.Formatter(
'%(asctime)s - %(name)-36s - %(levelname)-8s - %(message)s')
# add formatter to console handler and file handler
ch.setFormatter(formatter)
fh.setFormatter(formatter)
# add console handler and file handler to logger
logger.addHandler(ch)
logger.addHandler(fh)
if __name__=='__main__':
q = Queue()
name_list = ["A", "B", "C", "D"]
process_list = []
for i in range(0, len(name_list)):
process_list.append(Thread_class(name_list[i],q))
for i in range(0, len(process_list)):
process_list[i].start()
for i in range(0, len(process_list)):
process_list[i].join()
for i in range(0, len(process_list)):
#print(q.get())
print(process_list[i].test_return())