Pyt*_*ner 5 python logging python-multiprocessing
我正在创建一个多处理程序来处理多个批处理,但是我的日志记录无法将批处理记录到日志文件中,只会记录 root log.info,如何设置日志记录以正确打印到日志文件?
日志只会打印这样一行“INFO:root:this is root logging”
import logging
import concurrent.futures
def process_batchs():
batches = [i for i in range(100)]
logging.basicConfig(filename=r'doc\test_ProcessPoolExecutor.log', filemode='w+',level=logging.DEBUG)
logging.info('this is root logging')
with concurrent.futures.ProcessPoolExecutor(10) as e:
futures = []
for batch in batches:
future = e.submit(f, batch)
futures.append(future)
while True:
dones = [future.done() for future in futures]
if all(dones):
results = [future.result() for future in futures]
print results
break
def f(batch):
# do some thing
logging.info('this is sub logging' + str(batch))
return batch
if __name__ == '__main__':
process_batchs()
Run Code Online (Sandbox Code Playgroud)
在 windows/python2.7 上运行
| 归档时间: |
|
| 查看次数: |
1784 次 |
| 最近记录: |