Page MenuHomePhabricator

logging.RotatingFileHandler.doRollover fails with PermissionError
Open, LowPublicBUG REPORT

Description

The RotatingFileHandler.doRollover method of Python 3.11 sometimes fails with PermissionError if a second process blocks the logging file. I guess this is an upstream issue, the local implementation of RotatingFileHandler was dropped with Pywikibot 7.

############## LOGFILE SETTINGS ##############
log = ['*']
logfilesize = 4096
logfilecount = 99

The problem is that the throttle PID should prevent having the same logfile with different processes.

--- Logging error ---
Traceback (most recent call last):
  File "C:\Python311\Lib\logging\handlers.py", line 74, in emit
    self.doRollover()
  File "C:\Python311\Lib\logging\handlers.py", line 179, in doRollover
    self.rotate(self.baseFilename, dfn)
  File "C:\Python311\Lib\logging\handlers.py", line 115, in rotate
    os.rename(source, dest)
PermissionError: [WinError 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: 'D:\\pwb\\core\\logs\\redirect-bot.log' -> 'D:\\pwb\\core\\logs\\redirect-bot.1.log'
Call stack:
  File "D:\pwb\core\pwb.py", line 60, in <module>
    sys.exit(main())
  File "D:\pwb\core\pwb.py", line 48, in main
    runpy.run_path(str(path), run_name='__main__')
  File "<frozen runpy>", line 291, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "D:\pwb\core\pywikibot\scripts\wrapper.py", line 577, in <module>
    main()
  File "D:\pwb\core\pywikibot\scripts\wrapper.py", line 560, in main
    if not execute():
  File "D:\pwb\core\pywikibot\scripts\wrapper.py", line 547, in execute
    run_python_file(filename, script_args, module)
  File "D:\pwb\core\pywikibot\scripts\wrapper.py", line 154, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File "D:\pwb\core\scripts\redirect.py", line 954, in <module>
    main()
  File "D:\pwb\core\scripts\redirect.py", line 950, in main
    bot.run()
  File "D:\pwb\core\pywikibot\bot.py", line 1638, in run
    self.exit()
  File "D:\pwb\core\pywikibot\bot.py", line 1450, in exit
    pywikibot.info('successfully.')
  File "D:\pwb\core\pywikibot\logging.py", line 180, in info
    logoutput(msg, *args, **kwargs)
  File "D:\pwb\core\pywikibot\logging.py", line 152, in logoutput
    logger.log(level, msg, *args, extra=context, **kwargs)
Message: 'successfully.'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Python311\Lib\logging\handlers.py", line 74, in emit
    self.doRollover()
  File "C:\Python311\Lib\logging\handlers.py", line 179, in doRollover
    self.rotate(self.baseFilename, dfn)
  File "C:\Python311\Lib\logging\handlers.py", line 115, in rotate
    os.rename(source, dest)
PermissionError: [WinError 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: 'D:\\pwb\\core\\logs\\redirect-bot.log' -> 'D:\\pwb\\core\\logs\\redirect-bot.1.log'
Call stack:
  File "D:\pwb\core\pywikibot\comms\http.py", line 127, in flush
    log('Closing network session.')
  File "D:\pwb\core\pywikibot\logging.py", line 270, in log
    logoutput(msg, *args, level=VERBOSE, **kwargs)
  File "D:\pwb\core\pywikibot\logging.py", line 152, in logoutput
    logger.log(level, msg, *args, extra=context, **kwargs)
Message: 'Closing network session.'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "C:\Python311\Lib\logging\handlers.py", line 74, in emit
    self.doRollover()
  File "C:\Python311\Lib\logging\handlers.py", line 179, in doRollover
    self.rotate(self.baseFilename, dfn)
  File "C:\Python311\Lib\logging\handlers.py", line 115, in rotate
    os.rename(source, dest)
PermissionError: [WinError 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: 'D:\\pwb\\core\\logs\\redirect-bot.log' -> 'D:\\pwb\\core\\logs\\redirect-bot.1.log'
Call stack:
  File "D:\pwb\core\pywikibot\comms\http.py", line 145, in flush
    log('Network session closed.')
  File "D:\pwb\core\pywikibot\logging.py", line 270, in log
    logoutput(msg, *args, level=VERBOSE, **kwargs)
  File "D:\pwb\core\pywikibot\logging.py", line 152, in logoutput
    logger.log(level, msg, *args, extra=context, **kwargs)
Message: 'Network session closed.'
Arguments: ()

Event Timeline

Xqt triaged this task as Low priority.Sun, Oct 11, 12:04 PM
Xqt moved this task from Backlog to To upstream/missing upstream link on the Upstream board.
Xqt moved this task from Backlog to Upstream issues on the Pywikibot board.

Change #1354230 had a related patch set uploaded (by CoderAnimeshPathak; author: CoderAnimeshPathak):

[pywikibot/core@master] [bugfix] Fix RotatingFileHandler doRollover and throttle PID

https://gerrit.wikimedia.org/r/1354230