(self, pgexecute, special, callbacks, history=None, settings=None)
| 46 | return self._completer_thread and self._completer_thread.is_alive() |
| 47 | |
| 48 | def _bg_refresh(self, pgexecute, special, callbacks, history=None, settings=None): |
| 49 | settings = settings or {} |
| 50 | completer = PGCompleter(smart_completion=True, pgspecial=special, settings=settings) |
| 51 | |
| 52 | if settings.get("single_connection"): |
| 53 | executor = pgexecute |
| 54 | else: |
| 55 | # Create a new pgexecute method to populate the completions. |
| 56 | executor = pgexecute.copy() |
| 57 | # If callbacks is a single function then push it into a list. |
| 58 | if callable(callbacks): |
| 59 | callbacks = [callbacks] |
| 60 | |
| 61 | while 1: |
| 62 | for refresher in self.refreshers.values(): |
| 63 | refresher(completer, executor) |
| 64 | if self._restart_refresh.is_set(): |
| 65 | self._restart_refresh.clear() |
| 66 | break |
| 67 | else: |
| 68 | # Break out of while loop if the for loop finishes natually |
| 69 | # without hitting the break statement. |
| 70 | break |
| 71 | |
| 72 | # Start over the refresh from the beginning if the for loop hit the |
| 73 | # break statement. |
| 74 | continue |
| 75 | |
| 76 | # Load history into pgcompleter so it can learn user preferences |
| 77 | n_recent = 100 |
| 78 | if history: |
| 79 | for recent in history.get_strings()[-n_recent:]: |
| 80 | completer.extend_query_history(recent, is_init=True) |
| 81 | |
| 82 | for callback in callbacks: |
| 83 | callback(completer) |
| 84 | |
| 85 | if not settings.get("single_connection") and executor.conn: |
| 86 | # close connection established with pgexecute.copy() |
| 87 | executor.conn.close() |
| 88 | |
| 89 | |
| 90 | def refresher(name, refreshers=CompletionRefresher.refreshers): |
nothing calls this directly
no test coverage detected