# Buggy code
def watch_query(arg, **kwargs):
    usage = """Syntax: watch [seconds] [-c] query.
    * seconds: The interval at the query will be repeated, in seconds.
               By default 5.
    * -c: Clears the screen between every iteration.
"""
    if not arg:
        yield (None, None, None, usage)
        raise StopIteration
    seconds = 5
    clear_screen = False
    statement = None
    while statement is None:
        arg = arg.strip()
        if not arg:
            # Oops, we parsed all the arguments without finding a statement
            yield (None, None, None, usage)
            raise StopIteration
        (current_arg, _, arg) = arg.partition(" ")
        try:
            seconds = float(current_arg)
            continue
        except ValueError:
            pass
        if current_arg == "-c":
            clear_screen = True
            continue
        statement = "{0!s} {1!s}".format(current_arg, arg)
    destructive_prompt = confirm_destructive_query(statement)
    if destructive_prompt is False:
        click.secho("Wise choice!")
        raise StopIteration
    elif destructive_prompt is True:
        click.secho("Your call!")
    cur = kwargs["cur"]
    sql_list = [
        (sql.rstrip(";"), "> {0!s}".format(sql)) for sql in sqlparse.split(statement)
    ]
    old_pager_enabled = is_pager_enabled()
    while True:
        if clear_screen:
            click.clear()
        try:
            # Somewhere in the code the pager its activated after every yield,
            # so we disable it in every iteration
            set_pager_enabled(False)
            for sql, title in sql_list:
                cur.execute(sql)
                if cur.description:
                    headers = [x[0] for x in cur.description]
                    yield (title, cur, headers, None)
                else:
                    yield (title, None, None, None)
            sleep(seconds)
        except KeyboardInterrupt:
            # This prints the Ctrl-C character in its own line, which prevents
            # to print a line with the cursor positioned behind the prompt
            click.secho("", nl=True)
            raise StopIteration
        finally:
            set_pager_enabled(old_pager_enabled)


# Traceback (RuntimeError)
Traceback (most recent call last):
File "c:\python37\lib\site-packages\mycli\packages\parseutils.py", line 95, in extract_from_part
raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):w to complete suggestion
File "c:\python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "c:\python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:\python37\lib\site-packages\prompt_toolkit\interface.py", line 865, in run
completions = list(buffer.completer.get_completions(document, complete_event))
File "c:\python37\lib\site-packages\mycli\sqlcompleter.py", line 258, in get_completions
suggestions = suggest_type(document.text, document.text_before_cursor)
File "c:\python37\lib\site-packages\mycli\packages\completion_engine.py", line 93, in suggest_type
full_text, identifier)
File "c:\python37\lib\site-packages\mycli\packages\completion_engine.py", line 203, in suggest_based_on_last_token
return [{'type': 'column', 'tables': extract_tables(full_text)}]
File "c:\python37\lib\site-packages\mycli\packages\parseutils.py", line 154, in extract_tables
return list(extract_table_identifiers(stream))
File "c:\python37\lib\site-packages\mycli\packages\parseutils.py", line 113, in extract_table_identifiers
for item in token_stream:
RuntimeError: generator raised StopIteration

# Fixed code
def watch_query(arg, **kwargs):
    usage = """Syntax: watch [seconds] [-c] query.
    * seconds: The interval at the query will be repeated, in seconds.
               By default 5.
    * -c: Clears the screen between every iteration.
"""
    if not arg:
        yield (None, None, None, usage)
        return
    seconds = 5
    clear_screen = False
    statement = None
    while statement is None:
        arg = arg.strip()
        if not arg:
            # Oops, we parsed all the arguments without finding a statement
            yield (None, None, None, usage)
            return
        (current_arg, _, arg) = arg.partition(" ")
        try:
            seconds = float(current_arg)
            continue
        except ValueError:
            pass
        if current_arg == "-c":
            clear_screen = True
            continue
        statement = "{0!s} {1!s}".format(current_arg, arg)
    destructive_prompt = confirm_destructive_query(statement)
    if destructive_prompt is False:
        click.secho("Wise choice!")
        return
    elif destructive_prompt is True:
        click.secho("Your call!")
    cur = kwargs["cur"]
    sql_list = [
        (sql.rstrip(";"), "> {0!s}".format(sql)) for sql in sqlparse.split(statement)
    ]
    old_pager_enabled = is_pager_enabled()
    while True:
        if clear_screen:
            click.clear()
        try:
            # Somewhere in the code the pager its activated after every yield,
            # so we disable it in every iteration
            set_pager_enabled(False)
            for sql, title in sql_list:
                cur.execute(sql)
                if cur.description:
                    headers = [x[0] for x in cur.description]
                    yield (title, cur, headers, None)
                else:
                    yield (title, None, None, None)
            sleep(seconds)
        except KeyboardInterrupt:
            # This prints the Ctrl-C character in its own line, which prevents
            # to print a line with the cursor positioned behind the prompt
            click.secho("", nl=True)
            return
        finally:
            set_pager_enabled(old_pager_enabled)