More Windows thread oddness experimenting

This commit is contained in:
Dave Pearson
2023-05-17 11:02:04 +01:00
parent 80d00ce4bf
commit 6876a041a4

View File

@@ -3,7 +3,6 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from queue import Empty, Queue from queue import Empty, Queue
from threading import RLock
from typing import ClassVar, Iterable, Iterator from typing import ClassVar, Iterable, Iterator
from rich.style import Style from rich.style import Style
@@ -16,8 +15,6 @@ from ..reactive import var
from ..worker import Worker, get_current_worker from ..worker import Worker, get_current_worker
from ._tree import TOGGLE_STYLE, Tree, TreeNode from ._tree import TOGGLE_STYLE, Tree, TreeNode
read_dir = RLock()
@dataclass @dataclass
class DirEntry: class DirEntry:
@@ -270,11 +267,15 @@ class DirectoryTree(Tree[DirEntry]):
Yields: Yields:
Path: A entry within the location. Path: A entry within the location.
""" """
for entry in location.iterdir(): yield Path("Foo")
if worker.is_cancelled: yield Path("Bar")
break yield Path("Baz")
yield entry yield Path("Wibble")
self._tlog(f"Loaded entry {entry} from {location}") # for entry in location.iterdir():
# if worker.is_cancelled:
# break
# yield entry
# self._tlog(f"Loaded entry {entry} from {location}")
def _load_directory(self, node: TreeNode[DirEntry], worker: Worker) -> None: def _load_directory(self, node: TreeNode[DirEntry], worker: Worker) -> None:
"""Load the directory contents for a given node. """Load the directory contents for a given node.
@@ -284,15 +285,14 @@ class DirectoryTree(Tree[DirEntry]):
""" """
assert node.data is not None assert node.data is not None
node.data.loaded = True node.data.loaded = True
with read_dir: self.app.call_from_thread(
self.app.call_from_thread( self._populate_node,
self._populate_node, node,
node, sorted(
sorted( self.filter_paths(self._directory_content(node.data.path, worker)),
self.filter_paths(self._directory_content(node.data.path, worker)), key=lambda path: (not path.is_dir(), path.name.lower()),
key=lambda path: (not path.is_dir(), path.name.lower()), ),
), )
)
_LOADER_INTERVAL: Final[float] = 0.2 _LOADER_INTERVAL: Final[float] = 0.2
"""How long the loader should block while waiting for queue content.""" """How long the loader should block while waiting for queue content."""