MCPcopy Create free account
hub / github.com/dbcli/mycli / _bg_refresh

Method _bg_refresh

mycli/completion_refresher.py:53–100  ·  view source on GitHub ↗
(
        self,
        sqlexecute: SQLExecute,
        callbacks: Callable | list[Callable],
        completer_options: dict,
    )

Source from the content-addressed store, hash-verified

51 return bool(self._completer_thread and self._completer_thread.is_alive())
52
53 def _bg_refresh(
54 self,
55 sqlexecute: SQLExecute,
56 callbacks: Callable | list[Callable],
57 completer_options: dict,
58 ) -> None:
59 completer = SQLCompleter(**completer_options)
60
61 # Create a new sqlexecute method to populate the completions.
62 e = sqlexecute
63 try:
64 executor = SQLExecute(
65 e.dbname,
66 e.user,
67 e.password,
68 e.host,
69 e.port,
70 e.socket,
71 e.character_set,
72 e.local_infile,
73 e.ssl,
74 )
75 except pymysql.err.OperationalError:
76 return
77
78 # If callbacks is a single function then push it into a list.
79 if callable(callbacks):
80 callbacks = [callbacks]
81
82 while 1:
83 for refresher in self.refreshers.values():
84 refresher(completer, executor)
85 if self._restart_refresh.is_set():
86 self._restart_refresh.clear()
87 break
88 else:
89 # Break out of while loop if the for loop finishes natually
90 # without hitting the break statement.
91 break
92
93 # Start over the refresh from the beginning if the for loop hit the
94 # break statement.
95 continue
96
97 for callback in callbacks:
98 callback(completer)
99
100 executor.close()
101
102
103def refresher(name: str, refreshers: dict = CompletionRefresher.refreshers) -> Callable:

Calls 4

closeMethod · 0.95
SQLCompleterClass · 0.90
SQLExecuteClass · 0.90
refresherFunction · 0.70