Skip to content
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

Use Asyncio to execute #104

Open
mathben opened this issue Feb 11, 2023 · 1 comment
Open

Use Asyncio to execute #104

mathben opened this issue Feb 11, 2023 · 1 comment

Comments

@mathben
Copy link

mathben commented Feb 11, 2023

To increase speed of execution, I suggest to implement asyncio for each writer when command summary.

pygount/pygount/command.py

Lines 322 to 349 in fac7f7b

def execute(self):
_log.setLevel(logging.INFO if self.is_verbose else logging.WARNING)
source_scanner = pygount.analysis.SourceScanner(
self.source_patterns, self.suffixes, self.folders_to_skip, self.names_to_skip
)
source_paths_and_groups_to_analyze = list(source_scanner.source_paths())
duplicate_pool = pygount.analysis.DuplicatePool() if not self.has_duplicates else None
writer_class = _OUTPUT_FORMAT_TO_WRITER_CLASS_MAP[self.output_format]
is_stdout = self.output == "STDOUT"
target_context_manager = (
contextlib.nullcontext(sys.stdout) if is_stdout else open(self.output, "w", encoding="utf-8", newline="")
)
with target_context_manager as target_file, writer_class(target_file) as writer:
with Progress(disable=not writer.has_to_track_progress, transient=True) as progress:
try:
for source_path, group in progress.track(source_paths_and_groups_to_analyze):
writer.add(
pygount.analysis.SourceAnalysis.from_file(
source_path,
group,
self.default_encoding,
self.fallback_encoding,
generated_regexes=self._generated_regexs,
duplicate_pool=duplicate_pool,
)
)
finally:
progress.stop()

What do you think?

@roskakori
Copy link
Owner

Probably makes sense although the error reporting might need some changes with possibly multiple readers/writers failing at the same time.

Not high on my priority list though, but I leave it in the backlog.

@roskakori roskakori added this to the EuroPython 2024 Sprint milestone May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants