-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix in-cell slots #126
Fix in-cell slots #126
Changes from all commits
2a77031
25d1493
e8ae914
8a38478
1f2c044
a0dd108
68f90c6
12e08e1
d0156f3
c3bec90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import threading | ||
from types import ModuleType | ||
from typing import Callable, Generic, TypeVar | ||
import concurrent.futures | ||
|
||
THREAD: "threading.Thread | None" = None | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
@@ -22,26 +21,15 @@ class AsyncImporter(Generic[_T]): | |
|
||
def __init__(self, import_func: Callable[[], _T]) -> None: | ||
self._target = import_func | ||
self._thread: "threading.Thread | None" = None | ||
self._future: "concurrent.futures.Future[_T] | None" = None | ||
|
||
def run(self) -> None: | ||
with threading.Lock(): | ||
if self._thread is None: | ||
self._thread = threading.Thread(target=self._target, daemon=True) | ||
self._thread.start() | ||
else: | ||
self._thread.join() | ||
|
||
def get(self, ignore_error: bool = True) -> _T: | ||
try: | ||
self.run() | ||
except Exception as e: | ||
if ignore_error: | ||
return None | ||
else: | ||
raise e | ||
else: | ||
return self._target() | ||
if self._future is None or self._future.done(): | ||
self._future = concurrent.futures.ThreadPoolExecutor().submit(self._target) | ||
|
||
def get(self, timeout: float = None) -> _T: | ||
self.run() | ||
return self._future.result(timeout) | ||
|
||
__call__ = get | ||
|
||
Comment on lines
21
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,16 +77,6 @@ def value(self, val: str | SelectionOperator) -> None: | |
def format(self) -> str: | ||
return self._format | ||
|
||
def as_iloc(self) -> tuple[slice, slice]: | ||
"""Return current value as a indexer for ``iloc`` method.""" | ||
df = self._find_table().data_shown | ||
return self.value.as_iloc(df) | ||
|
||
def as_iloc_slices(self) -> tuple[slice, slice]: | ||
"""Return current value as slices for ``iloc`` method.""" | ||
df = self._find_table().data_shown | ||
return self.value.as_iloc_slices(df) | ||
|
||
def _find_table(self) -> TableBase: | ||
table = find_current_table(self) | ||
if table is None: | ||
Comment on lines
81
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The def _find_table(self) -> TableBase:
table = find_current_table(self)
if table is None:
+ raise ValueError("No current table found.") |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new
ThreadPoolExecutor
each time therun()
method is called can be inefficient and lead to resource leaks if the executor is not properly shut down. It would be better to create a single executor instance and reuse it for all tasks. Here's how you might do this: