1

I'm trying to understand why the same set of code works in osx but not in windows.

logger_name = 'gic_scheduler'
logger = logging.getLogger(logger_name)
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
fh = logging.FileHandler(filename=os.path.join(tmp_folder, 'scheduler.log'), encoding='utf-8')
fh.setLevel(logging.DEBUG)

logger.addHandler(ch)
logger.addHandler(fh)

executor_logger = logging.getLogger('apscheduler.executors.default')
executor_logger.setLevel(logging.DEBUG)
executor_logger.addHandler(ch)
executor_logger.addHandler(fh)

executors = {'default': ProcessPoolExecutor(5)}

scheduler = BlockingScheduler(executors=executors, logger=logger)

scheduler.add_job(go, 'interval', seconds=5)    
scheduler.start()

In particular, no output is produced by the logger 'apscheduler.executors.default'. I digged into the 3rd party library using this logger and printed out logger.handlers and in OSX's case the handlers are there but in Windows they are empty. Any ideas why?

def run_job(job, jobstore_alias, run_times, logger_name):
    """Called by executors to run the job. Returns a list of scheduler events to be dispatched by the scheduler."""

    events = []
    logger = logging.getLogger(logger_name)
    print logger_name
    print logger.handlers
goh
  • 27,631
  • 28
  • 89
  • 151
  • Probably you're relying on the logging configuration getting inherited via `fork`, but Windows *spawns* new process via `CreateProcess`. See [this answer](http://stackoverflow.com/a/1009560) for a `logging.Handler` subclass that uses a `multiprocessing.Queue`. The pool initializer sets up the handler and logging level in each worker process. – Eryk Sun Mar 20 '15 at 14:48
  • yes @eryksun, apparently I missed the documentation where logging configurations does not pass over to child processes. If u put it as an answer I'll accept it. – goh Mar 24 '15 at 10:32

0 Answers0