Skip to content
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
3 changes: 1 addition & 2 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Python package
on: [push]

jobs:
build:

test:
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.5

- PreprocessorExt: fixed the definition of `run_in_thread`, which is a decorator for the file processing function.

# 1.0.4

- utils: add `move_files_threadpool` function
Expand Down
25 changes: 17 additions & 8 deletions foliant/preprocessors/utils/preprocessor_ext.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import os
import re
import traceback
import threading

from pathlib import Path
from typing import Callable
from typing import Optional
from typing import Union
from typing import Callable, Optional, Union
from functools import wraps

from foliant.preprocessors.base import BasePreprocessor
from foliant.utils import output


MAX_THREADS = max(1, os.cpu_count() - 2)
thread_semaphore = threading.Semaphore(MAX_THREADS)

def run_in_thread(fn):
def run(*k, **kw):
t = threading.Thread(target=fn, args=k, kwargs=kw)
t.start()
return t
return run
@wraps(fn)
def run(*args, **kwargs):
def wrapper():
try:
fn(*args, **kwargs)
finally:
thread_semaphore.release()

thread_semaphore.acquire()
threading.Thread(target=wrapper, daemon=True).start()

return run

def allow_fail(msg: str = 'Failed to process tag. Skipping.') -> Callable:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
description=SHORT_DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
version='1.0.4',
version='1.0.5',
author='Daniil Minukhin',
author_email='ddddsa@gmail.com',
url='https://github.com/foliant-docs/foliantcontrib.utils',
Expand Down