# Buggy code
def _on_show_prompts(self, question):
    """Show a prompt for the given question.

    Args:
        question: A Question object or None.
    """
    item = self._layout.takeAt(0)
    if item is not None:
        widget = item.widget()
        log.prompt.debug("Deleting old prompt {}".format(widget))
        widget.hide()
        widget.deleteLater()

    if question is None:
        log.prompt.debug("No prompts left, hiding prompt container.")
        self._prompt = None
        self.hide()
        return

    classes = {
        usertypes.PromptMode.yesno: YesNoPrompt,
        usertypes.PromptMode.text: LineEditPrompt,
        usertypes.PromptMode.user_pwd: AuthenticationPrompt,
        usertypes.PromptMode.download: DownloadFilenamePrompt,
        usertypes.PromptMode.alert: AlertPrompt,
    }
    klass = classes[question.mode]
    prompt = klass(question)

    log.prompt.debug("Displaying prompt {}".format(prompt))
    self._prompt = prompt

    if not question.interrupted:
        # If this question was interrupted, we already connected the signal
        question.aborted.connect(
            lambda: modeman.leave(self._win_id, prompt.KEY_MODE, "aborted", maybe=True)
        )
    modeman.enter(self._win_id, prompt.KEY_MODE, "question asked")

    self.setSizePolicy(prompt.sizePolicy())
    self._layout.addWidget(prompt)
    prompt.show()
    self.show()
    prompt.setFocus()
    self.update_geometry.emit()


# Traceback (AttributeError)
13:11:06 DEBUG    modes      tabbedbrowser:on_mode_left:618 Left status-input mode, focusing <qutebrowser.browser.webengine.webenginetab.WebEngineTab tab_id=1 url='https://[...].slack.com/messages/[...]/convo/[...]/'>
13:11:06 DEBUG    modes      modeman:leave:290 Ignoring leave request for KeyMode.prompt (reason aborted) as we're in mode KeyMode.normal
[...]
13:11:06 ERROR    misc       crashsignal:exception_hook:216 Uncaught exception
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/qutebrowser/utils/objreg.py", line 200, in _get_window_registry
return win.registry
AttributeError: 'NoneType' object has no attribute 'registry'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/qutebrowser/mainwindow/prompt.py", line 335, in <lambda>
maybe=True))
File "/usr/lib/python3.6/site-packages/qutebrowser/keyinput/modeman.py", line 109, in leave
instance(win_id).leave(mode, reason, maybe=maybe)
File "/usr/lib/python3.6/site-packages/qutebrowser/keyinput/modeman.py", line 99, in instance
return objreg.get('mode-manager', scope='window', window=win_id)
File "/usr/lib/python3.6/site-packages/qutebrowser/utils/objreg.py", line 227, in get
reg = _get_registry(scope, window, tab)
File "/usr/lib/python3.6/site-packages/qutebrowser/utils/objreg.py", line 216, in _get_registry
return _get_window_registry(window)
File "/usr/lib/python3.6/site-packages/qutebrowser/utils/objreg.py", line 202, in _get_window_registry
raise RegistryUnavailableError('window')
qutebrowser.utils.objreg.RegistryUnavailableError: window

# Fixed code
def _on_show_prompts(self, question):
    """Show a prompt for the given question.

    Args:
        question: A Question object or None.
    """
    item = self._layout.takeAt(0)
    if item is not None:
        widget = item.widget()
        log.prompt.debug("Deleting old prompt {}".format(widget))
        widget.hide()
        widget.deleteLater()

    if question is None:
        log.prompt.debug("No prompts left, hiding prompt container.")
        self._prompt = None
        self.hide()
        return

    classes = {
        usertypes.PromptMode.yesno: YesNoPrompt,
        usertypes.PromptMode.text: LineEditPrompt,
        usertypes.PromptMode.user_pwd: AuthenticationPrompt,
        usertypes.PromptMode.download: DownloadFilenamePrompt,
        usertypes.PromptMode.alert: AlertPrompt,
    }
    klass = classes[question.mode]
    prompt = klass(question)

    log.prompt.debug("Displaying prompt {}".format(prompt))
    self._prompt = prompt

    if not question.interrupted:
        # If this question was interrupted, we already connected the signal
        def on_aborted():
            try:
                modeman.leave(self._win_id, prompt.KEY_MODE, "aborted", maybe=True)
            except objreg.RegistryUnavailableError:
                # window was deleted: ignore
                pass

        question.aborted.connect(on_aborted)
    modeman.enter(self._win_id, prompt.KEY_MODE, "question asked")

    self.setSizePolicy(prompt.sizePolicy())
    self._layout.addWidget(prompt)
    prompt.show()
    self.show()
    prompt.setFocus()
    self.update_geometry.emit()