Skip to content

Commit

Permalink
Merge pull request #76 from python-thread/feature/v2.0.0
Browse files Browse the repository at this point in the history
v2.0.0


Signed-off-by: AlexNg <[email protected]>
  • Loading branch information
caffeine-addictt authored Apr 21, 2024
2 parents 8f1ad08 + 5750f33 commit 9217bbc
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 98 deletions.
10 changes: 5 additions & 5 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ identifiers:
value: 10.5281/zenodo.10799219
description: This is the collection of archived snapshots of all versions of thread.
- type: url
value: https://github.com/python-thread/thread/releases/tag/v1.1.1
description: The GitHub release URL of tag v1.1.1.
value: https://github.com/python-thread/thread/releases/tag/v2.0.0
description: The GitHub release URL of tag v2.0.0.
- type: url
value: https://pypi.org/project/thread/1.1.1
description: The PyPI release URL of tag v1.1.1.
value: https://pypi.org/project/thread/2.0.0
description: The PyPI release URL of tag v2.0.0.
cff-version: 1.2.0
date-released: 2024-03-07
keywords:
Expand All @@ -32,6 +32,6 @@ repository-code: https://github.com/python-thread/thread
repository-artifact: https://pypi.org/project/thread
title: thread
type: software
version: 1.1.1
version: 2.0.0
url: https://thread.ngjx.org

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _Below is an example of how you can install and use thread._
2. Import thread into your library!
```py
import thread
from thread import Thread, ParallelProcessing
from thread import Thread, ConcurrentProcessing
```

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand All @@ -98,7 +98,7 @@ Our docs are [here!](https://thread.ngjx.org)
<!-- ROADMAP -->
## Roadmap

- [x] v1.1.1 Release
- [x] v2.0.0 Release
- [ ] Bug fixes
- [ ] New features
- [ ] Testing
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "thread"
version = "1.1.1"
version = "2.0.0"
description = "Threading module extension"
authors = ["Alex <[email protected]>"]
license = "BSD-3-Clause"
Expand Down Expand Up @@ -30,7 +30,7 @@ classifiers = [

[tool.poetry.urls]
Homepage = "https://thread.ngjx.org"
Documentation = "https://thread.ngjx.org/docs/v1.1.1"
Documentation = "https://thread.ngjx.org/docs/v2.0.0"
Source = "https://github.com/python-thread/thread"
Download = "https://pypi.org/project/thread/#files"
"Release Notes" = "https://github.com/python-thread/thread/releases"
Expand Down
10 changes: 5 additions & 5 deletions src/thread/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
## Thread Library
Documentation at https://thread.ngjx.org/docs/v1.1.1
Documentation at https://thread.ngjx.org/docs/2.0.0
---
Released under the GPG-3 License
Released under the BSD-3 License
Copyright (c) thread.ngjx.org, All rights reserved
"""
Expand All @@ -18,11 +18,11 @@
"""


__version__ = '1.1.1'
__version__ = '2.0.0'


# Export Core
from .thread import Thread, ParallelProcessing
from .thread import Thread, ConcurrentProcessing


from . import _types as types, exceptions
Expand All @@ -39,7 +39,7 @@
# Wildcard Export
__all__ = [
'Thread',
'ParallelProcessing',
'ConcurrentProcessing',
'threaded',
'processor',
'types',
Expand Down
2 changes: 1 addition & 1 deletion src/thread/_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
## Types
Documentation: https://thread.ngjx.org/docs/v1.1.1
Documentation: https://thread.ngjx.org/docs/v2.0.0
"""

from typing import Any, Literal, Callable, Union, Sized
Expand Down
21 changes: 12 additions & 9 deletions src/thread/decorators/_processor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
## Processor
Documentation: https://thread.ngjx.org/docs/v1.1.1
Documentation: https://thread.ngjx.org/docs/v2.0.0
"""

from functools import wraps
from ..thread import ParallelProcessing
from ..thread import ConcurrentProcessing

from .._types import (
Overflow_In,
Expand All @@ -29,22 +29,23 @@

NoParamReturn = Callable[
Concatenate[Dataset[_DataT], _TargetP],
ParallelProcessing[_TargetP, _TargetT, _DataT],
ConcurrentProcessing[_TargetP, _TargetT, _DataT],
]
WithParamReturn = Callable[
[TargetFunction[_DataT, _TargetP, _TargetT]],
NoParamReturn[_DataT, _TargetP, _TargetT],
]
FullParamReturn = Callable[
Concatenate[Dataset[_DataT], _TargetP],
ParallelProcessing[_TargetP, _TargetT, _DataT],
ConcurrentProcessing[_TargetP, _TargetT, _DataT],
]


@overload
def processor(
__function: TargetFunction[_DataT, _TargetP, _TargetT],
) -> NoParamReturn[_DataT, _TargetP, _TargetT]: ...
) -> NoParamReturn[_DataT, _TargetP, _TargetT]:
...


@overload
Expand All @@ -55,7 +56,8 @@ def processor(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> WithParamReturn[_DataT, _TargetP, _TargetT]: ...
) -> WithParamReturn[_DataT, _TargetP, _TargetT]:
...


@overload
Expand All @@ -67,7 +69,8 @@ def processor(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> FullParamReturn[_DataT, _TargetP, _TargetT]: ...
) -> FullParamReturn[_DataT, _TargetP, _TargetT]:
...


def processor(
Expand Down Expand Up @@ -150,15 +153,15 @@ def wrapped(
data: Dataset[_DataT],
*parsed_args: _TargetP.args,
**parsed_kwargs: _TargetP.kwargs,
) -> ParallelProcessing[_TargetP, _TargetT, _DataT]:
) -> ConcurrentProcessing[_TargetP, _TargetT, _DataT]:
kwargs.update(parsed_kwargs)

processed_args = (*args, *parsed_args)
processed_kwargs = {
i: v for i, v in kwargs.items() if i not in ['args', 'kwargs']
}

job = ParallelProcessing(
job = ConcurrentProcessing(
function=__function,
dataset=data,
args=processed_args,
Expand Down
11 changes: 7 additions & 4 deletions src/thread/decorators/_threaded.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
## Threaded
Documentation: https://thread.ngjx.org/docs/v1.1.1
Documentation: https://thread.ngjx.org/docs/v2.0.0
"""

from functools import wraps
Expand All @@ -23,7 +23,8 @@


@overload
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]: ...
def threaded(__function: TargetFunction[P, T]) -> NoParamReturn[P, T]:
...


@overload
Expand All @@ -34,7 +35,8 @@ def threaded(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> WithParamReturn[P, T]: ...
) -> WithParamReturn[P, T]:
...


@overload
Expand All @@ -46,7 +48,8 @@ def threaded(
ignore_errors: Sequence[type[Exception]] = (),
suppress_errors: bool = False,
**overflow_kwargs: Overflow_In,
) -> FullParamReturn[P, T]: ...
) -> FullParamReturn[P, T]:
...


def threaded(
Expand Down
2 changes: 1 addition & 1 deletion src/thread/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
## Thread Exceptions
Documentation: https://thread.ngjx.org/docs/v1.1.1
Documentation: https://thread.ngjx.org/docs/v2.0.0
"""

import traceback
Expand Down
38 changes: 16 additions & 22 deletions src/thread/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class Thread: ...
class ParallelProcessing: ...
class ConcurrentProcessing: ...
```
Documentation: https://thread.ngjx.org/docs/v1.1.1
Documentation: https://thread.ngjx.org/docs/v2.0.0
"""

import sys
Expand Down Expand Up @@ -230,18 +230,14 @@ def add_hook(self, hook: HookFunction[_Target_T]) -> None:
"""
self.hooks.append(hook)

def join(self, timeout: Optional[float] = None) -> bool:
def join(self, timeout: Optional[float] = None) -> None:
"""
Halts the current thread execution until a thread completes or exceeds the timeout
Parameters
----------
:param timeout: The maximum time allowed to halt the thread
Returns
-------
:returns bool: True if the thread is no-longer alive
Raises
------
ThreadNotInitializedError: If the thread is not initialized
Expand All @@ -255,7 +251,6 @@ def join(self, timeout: Optional[float] = None) -> bool:

super().join(timeout)
self._handle_exceptions()
return not self.is_alive()

def get_return_value(self) -> _Target_T:
"""
Expand Down Expand Up @@ -341,9 +336,9 @@ def __init__(self, thread: Thread, progress: float = 0) -> None:
self.progress = progress


class ParallelProcessing(Generic[_Target_P, _Target_T, _Dataset_T]):
class ConcurrentProcessing(Generic[_Target_P, _Target_T, _Dataset_T]):
"""
Multi-Threaded Parallel Processing
Concurrent Processing
---------------------------------------
Type-Safe and provides more functionality on top
Expand Down Expand Up @@ -378,7 +373,8 @@ def __init__(
_get_value: Optional[Callable[[LengthandGetLike_T, int], _Dataset_T]] = None,
_length: Optional[Union[int, Callable[[Any], int]]] = None,
**overflow_kwargs: Overflow_In,
) -> None: ...
) -> None:
...

# Has __len__, require _get_value to be set
@overload
Expand All @@ -391,7 +387,8 @@ def __init__(
_get_value: Callable[[LengthLike_T, int], _Dataset_T],
_length: Optional[Union[int, Callable[[Any], int]]] = None,
**overflow_kwargs: Overflow_In,
) -> None: ...
) -> None:
...

# Has __getitem__, require _length to be set
@overload
Expand All @@ -404,7 +401,8 @@ def __init__(
_get_value: Optional[Callable[[GetLike_T, int], _Dataset_T]] = None,
_length: Union[int, Callable[[GetLike_T], int]],
**overflow_kwargs: Overflow_In,
) -> None: ...
) -> None:
...

# Does not support __getitem__ and __len__
@overload
Expand All @@ -417,7 +415,8 @@ def __init__(
_get_value: Callable[[Any, int], _Dataset_T],
_length: Union[int, Callable[[Any], int]],
**overflow_kwargs: Overflow_In,
) -> None: ...
) -> None:
...

def __init__(
self,
Expand All @@ -442,10 +441,10 @@ def __init__(
**overflow_kwargs: Overflow_In,
) -> None:
"""
Initializes a new Multi-Threaded Pool\n
Initializes a new Concurrent Process\n
Best for data processing
Splits a dataset as evenly as it can among the threads and run them in parallel
Splits a dataset as evenly as it can among the threads and run them concurrently
Parameters
----------
Expand Down Expand Up @@ -598,14 +597,10 @@ def get_return_values(self) -> List[_Dataset_T]:
results += entry.thread.result
return results

def join(self) -> bool:
def join(self) -> None:
"""
Halts the current thread execution until a thread completes or exceeds the timeout
Returns
-------
:returns bool: True if the thread is no-longer alive
Raises
------
ThreadNotInitializedError: If the thread is not initialized
Expand All @@ -619,7 +614,6 @@ def join(self) -> bool:

for entry in self._threads:
entry.thread.join()
return True

def kill(self) -> None:
"""
Expand Down
Loading

0 comments on commit 9217bbc

Please sign in to comment.