当我在Windows电脑上运行以下脚本时,我看不到来自log_pid函数的任何日志消息,但在Unix / Mac上运行时会看到。我之前曾读过,与Mac相比,在Windows上的多进程处理有所不同,但我不清楚应该做出什么更改才能使此脚本在Windows上正常工作。我正在运行Python 3.6。
import logging
import sys
from concurrent.futures import ProcessPoolExecutor
import os
def log_pid(x):
logger.info('Executing on process: %s' % os.getpid())
def do_stuff():
logger.info('this is the do stuff function.')
with ProcessPoolExecutor(max_workers=4) as executor:
executor.map(log_pid, range(0, 10))
def main():
logger.info('this is the main function.')
do_stuff()
if __name__ == '__main__':
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.info('Start of script ...')
main()
logger.info('End of script ...')