Page MenuHomePhabricator

atexit callback fails if an exception is raised in a very early state
Closed, ResolvedPublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • uninstall wikitextparser and mwparserfromhell
  • run pwb

What happens?:

C:\pwb\GIT\core>pwb

Pywikibot is missing a MediaWiki markup parser which is necessary.
Please update the required module with either

    pip install "mwparserfromhell>=0.5.0"

or

    pip install "wikitextparser>=0.47.5"

Exception ignored in atexit callback: <function flush at 0x0000020C5DDD2EF0>
Traceback (most recent call last):
  File "C:\pwb\GIT\core\pywikibot\comms\http.py", line 88, in flush
    log('Closing network session.')
  File "C:\pwb\GIT\core\pywikibot\logging.py", line 193, in log
    logoutput(text, decoder, newline, VERBOSE, **kwargs)
  File "C:\pwb\GIT\core\pywikibot\logging.py", line 79, in logoutput
    _init()
  File "C:\pwb\GIT\core\pywikibot\logging.py", line 38, in _init
    init_routine()
  File "C:\pwb\GIT\core\pywikibot\tools\_deprecate.py", line 487, in wrapper
    return obj(*new_args, **new_kwargs)
  File "C:\pwb\GIT\core\pywikibot\bot.py", line 398, in init_handlers
    if pywikibot.Site.__doc__ != 'TEST':  # set by aspects.DisableSiteMixin
AttributeError: module 'pywikibot' has no attribute 'Site'

C:\pwb\GIT\core>

The reason might be that pywikibot.bot is not fully imported and the logger handler is not initialized when the atexit callback is called in this early state.

What should have happened instead?:

No exception should be shown

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:
Pywikibot 7.0 (master), 6.6.3 (stable). 6.5, 6.4, 6.3. It works as expected with 6.2

Event Timeline

Xqt triaged this task as Medium priority.Dec 30 2021, 8:11 AM

Change 750698 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] Don't greate a Site object if pywikibot is not fully imported

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

Change 750698 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Don't create a Site object if pywikibot is not fully imported

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

Xqt claimed this task.