functionalthreading 0.3.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/PKG-INFO +1 -1
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading/__init__.py +2 -1
- functionalthreading-0.5.0/functionalthreading/classes/__init__.py +50 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading/functions/__init__.py +4 -17
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/PKG-INFO +1 -1
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/SOURCES.txt +1 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/pyproject.toml +1 -1
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/setup.py +5 -1
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/LICENSE +0 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/README.md +0 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/dependency_links.txt +0 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/top_level.txt +0 -0
- {functionalthreading-0.3.0 → functionalthreading-0.5.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: functionalthreading
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Functional programming with thread-based parallelism
|
|
5
5
|
Author-email: Richard Tong <richytong@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/richytong/functionalthreading
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from functools import partial, Placeholder as _
|
|
2
2
|
from functionalthreading.functions import chain, tap, tmap
|
|
3
|
+
from functionalthreading.classes import Thread
|
|
3
4
|
|
|
4
5
|
__name__ = 'functionalthreading'
|
|
5
6
|
|
|
6
|
-
__all__ = ['partial', '_' ,'chain', 'tap', 'tmap']
|
|
7
|
+
__all__ = ['Thread', 'partial', '_' ,'chain', 'tap', 'tmap']
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from threading import Thread as _Thread
|
|
2
|
+
|
|
3
|
+
class Thread(_Thread):
|
|
4
|
+
"""Represents an execution that is run in a thread.
|
|
5
|
+
|
|
6
|
+
A thread is an independent unit of a process that is scheduled by the operating system's thread scheduler and can be run concurrently.
|
|
7
|
+
|
|
8
|
+
After the target invocation, the result of the invocation is stored under the `result` property of the thread.
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
def f(n):
|
|
12
|
+
return n ** 2
|
|
13
|
+
|
|
14
|
+
t = Thread(target=f, args=[3])
|
|
15
|
+
t.start()
|
|
16
|
+
t.join()
|
|
17
|
+
print(t.result)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Methods: [start](https://docs.python.org/3/library/threading.html#threading.Thread.start), [join](https://docs.python.org/3/library/threading.html#threading.Thread.start)
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
def __init__(self, **kwargs):
|
|
24
|
+
"""The constructor should always be called with keyword arguments. Arguments are:
|
|
25
|
+
|
|
26
|
+
target - the callable object to be invoked.
|
|
27
|
+
|
|
28
|
+
args - a list or tuple of arguments for the target invocation.
|
|
29
|
+
|
|
30
|
+
kwargs - a dictionary of keyword arguments for the target invocation.
|
|
31
|
+
|
|
32
|
+
daemon - explicitly sets whether the thread is daemonic. If `None` (the default), the daemonic property is inherited from the current thread.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
_Thread.__init__(self, **kwargs)
|
|
36
|
+
self.result = None
|
|
37
|
+
self._target = kwargs['target']
|
|
38
|
+
self._args = ()
|
|
39
|
+
self._kwargs = {}
|
|
40
|
+
if 'args' in kwargs:
|
|
41
|
+
self._args = kwargs['args']
|
|
42
|
+
if 'kwargs' in kwargs:
|
|
43
|
+
self._kwargs = kwargs['kwargs']
|
|
44
|
+
|
|
45
|
+
def run(self):
|
|
46
|
+
self.result = self._target(*self._args, **self._kwargs)
|
|
47
|
+
|
|
48
|
+
__name__ = 'classes'
|
|
49
|
+
|
|
50
|
+
__all__ = ['Thread']
|
{functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading/functions/__init__.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from functools import partial, Placeholder as _
|
|
2
|
-
from
|
|
2
|
+
from functionalthreading.classes import Thread
|
|
3
3
|
|
|
4
4
|
def _chain(argument, funcs):
|
|
5
5
|
ret = argument
|
|
@@ -61,33 +61,20 @@ def tap(func):
|
|
|
61
61
|
return argument
|
|
62
62
|
return inner_func
|
|
63
63
|
|
|
64
|
-
class _Thread(Thread):
|
|
65
|
-
def __init__(self, *args, **kwargs):
|
|
66
|
-
Thread.__init__(self, *args, **kwargs)
|
|
67
|
-
self.value = None
|
|
68
|
-
self.target = kwargs['target']
|
|
69
|
-
self.args = kwargs['args']
|
|
70
|
-
|
|
71
|
-
def run(self):
|
|
72
|
-
self.value = self.target(*self.args)
|
|
73
|
-
|
|
74
64
|
def _tmap(array_or_tuple, func):
|
|
75
65
|
length = len(array_or_tuple)
|
|
76
66
|
threads = []
|
|
77
67
|
index = 0
|
|
78
68
|
args = [array_or_tuple]
|
|
79
69
|
while index < length:
|
|
80
|
-
t =
|
|
70
|
+
t = Thread(target=func, args=[array_or_tuple[index]])
|
|
81
71
|
t.start()
|
|
82
72
|
threads.append(t)
|
|
83
73
|
index += 1
|
|
84
|
-
index = 0
|
|
85
74
|
result = []
|
|
86
|
-
|
|
87
|
-
t = threads[index]
|
|
75
|
+
for t in threads:
|
|
88
76
|
t.join()
|
|
89
|
-
result.append(t.
|
|
90
|
-
index += 1
|
|
77
|
+
result.append(t.result)
|
|
91
78
|
if isinstance(array_or_tuple, tuple):
|
|
92
79
|
return tuple(result)
|
|
93
80
|
return result
|
{functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: functionalthreading
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Functional programming with thread-based parallelism
|
|
5
5
|
Author-email: Richard Tong <richytong@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/richytong/functionalthreading
|
|
@@ -8,5 +8,9 @@ with open('pyproject.toml', 'rb') as file:
|
|
|
8
8
|
name='functionalthreading',
|
|
9
9
|
version=pyproject['project']['version'],
|
|
10
10
|
description='Functional programming with thread-based parallelism',
|
|
11
|
-
packages=[
|
|
11
|
+
packages=[
|
|
12
|
+
'functionalthreading',
|
|
13
|
+
'functionalthreading.classes',
|
|
14
|
+
'functionalthreading.functions',
|
|
15
|
+
],
|
|
12
16
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{functionalthreading-0.3.0 → functionalthreading-0.5.0}/functionalthreading.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|