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

Revert pysub2 versioning to fix crashing multiprocessing pool threads #9

Merged
merged 11 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Docker

on:
push:
branches: [ "main" ]
branches: [ "main","dev"]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
Expand Down
4 changes: 1 addition & 3 deletions actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ def events_action_delete(ssafile: SSAFile, event: SSAEvent, **kwargs):
ssafile.events.remove(event)


def events_misc_remove_miscellaneous_events(
ssafile: SSAFile, **kwargs
):
def events_misc_remove_miscellaneous_events(ssafile: SSAFile, **kwargs):
ssafile.remove_miscellaneous_events()
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ def postprocess_subtitles(files, args, pp_args):

postprocesser = postprocessing.SubtitleFormatter(pp_args.postprocessing)

run(args.threads, postprocesser.format, files, args.disable_progress_bar)
output = run(args.threads, postprocesser.format, files, args.disable_progress_bar)
output_files = list(chain.from_iterable(output))

if args.exclude_mode == "e+a" and pp_args.exclude_subtitles != None:
with open(pp_args.exclude_subtitles, "a") as f:
f.write("\n".join(files))
f.write("\n".join(output_files))

return files
return output_files


def extract_subtitles(files, args, vid_args):
Expand Down
15 changes: 15 additions & 0 deletions postprocess.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# DEFINING A TASK:
# Order of operation:
# 1) selectors: Select objects to be processed
# - func(ssafile, **kwargs) -> obj
# 2) filter: filter out object from selectors
# - func(ssafile, item, **kwargs) -> bool
# 3) actions: run actions for each item that was selected
# - func(ssafile, item, **kwargs) -> output
# 4) run misc function
# - func(ssafile,**kwargs) -> output
#
# defining id saves the output of an action to a dict: outputs
# the value can be accessed using: {{outputs['id'][0]['PlayResX']}}
#

ass:
tasks:
- selectors:
Expand Down
6 changes: 3 additions & 3 deletions postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def format(self, path, save=True):
runner = SubtitleRunner(self.workflows[ext])
self.log.debug(f"Formatting subtitle: {path}")

return runner.format(path, save=save)
runner.format(path, save=save)
return path

else:
logger.warning("Unsupported format, skipping...")
return None
raise ValueError(f"Unsupported format: {path}")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
babelfish==0.6.1
cachetools==5.3.3
pgsrip==0.1.11
pysubs2==1.7.2
pysubs2==1.6.1
PyYAML==6.0.1
tqdm_loggable==0.2
watchdog==4.0.1
30 changes: 18 additions & 12 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import traceback
from itertools import chain
import functools

from tqdm_loggable.auto import tqdm
from tqdm_loggable.tqdm_logging import tqdm_logging
Expand All @@ -18,32 +19,37 @@
def run(threads, function, files, disable_progress_bar=False):

with tqdm(total=len(files), unit="file", disable=disable_progress_bar) as pbar:
run_output = []

def _run_callback(out):
nonlocal run_output
output = []

def _run_callback(result):
nonlocal pbar
nonlocal output

pbar.update(1)
run_output.append(out)
output.append(result)

def _error_callback(e):
logger.critical(
f"An Error occurred in thread...: {''.join(traceback.format_exception(e))}"
)
def _error_callback(error):
nonlocal pbar
nonlocal output

with multiprocessing.Pool(threads) as pool:
pbar.update(1)
logger.critical(f"An error occurred in thread....")
traceback.print_exception(type(error), error, error.__traceback__)

for i in range(pbar.total):
with multiprocessing.Pool(threads) as pool:
for fp in files:
pool.apply_async(
function,
args=(files[i],),
args=(fp,),
callback=_run_callback,
error_callback=_error_callback,
)

pool.close()
pool.join()

return run_output
return output


def get_filelist(path, regex, excluded_files=[]):
Expand Down
Loading