Create a new history manager associated with a shell instance.
(
self,
shell: InteractiveShell,
config: Optional[Configuration] = None,
**traits: typing.Any,
)
| 678 | _max_inst: int | float = float("inf") |
| 679 | |
| 680 | def __init__( |
| 681 | self, |
| 682 | shell: InteractiveShell, |
| 683 | config: Optional[Configuration] = None, |
| 684 | **traits: typing.Any, |
| 685 | ): |
| 686 | """Create a new history manager associated with a shell instance.""" |
| 687 | super().__init__(shell=shell, config=config, **traits) |
| 688 | self.db_input_cache_lock = threading.Lock() |
| 689 | self.db_output_cache_lock = threading.Lock() |
| 690 | |
| 691 | try: |
| 692 | self.new_session() |
| 693 | except OperationalError: |
| 694 | self.log.error( |
| 695 | "Failed to create history session in %s. History will not be saved.", |
| 696 | self.hist_file, |
| 697 | exc_info=True, |
| 698 | ) |
| 699 | self._switch_to_memory_history() |
| 700 | |
| 701 | self.using_thread = False |
| 702 | if self.enabled and self.hist_file != ":memory:": |
| 703 | self.save_thread = HistorySavingThread(self) |
| 704 | try: |
| 705 | self.save_thread.start() |
| 706 | except RuntimeError: |
| 707 | self.log.error( |
| 708 | "Failed to start history saving thread. History will not be saved.", |
| 709 | exc_info=True, |
| 710 | ) |
| 711 | self._switch_to_memory_history() |
| 712 | self.save_thread = None |
| 713 | else: |
| 714 | self.using_thread = True |
| 715 | self._instances.add(self) |
| 716 | assert len(HistoryManager._instances) <= HistoryManager._max_inst, ( |
| 717 | len(HistoryManager._instances), |
| 718 | HistoryManager._max_inst, |
| 719 | ) |
| 720 | |
| 721 | def _switch_to_memory_history(self) -> None: |
| 722 | """Switch history storage to an in-memory SQLite database.""" |
no test coverage detected