functionalthreading 0.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: functionalthreading
3
- Version: 0.4.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
@@ -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']
@@ -71,13 +71,10 @@ def _tmap(array_or_tuple, func):
71
71
  t.start()
72
72
  threads.append(t)
73
73
  index += 1
74
- index = 0
75
74
  result = []
76
- while index < length:
77
- t = threads[index]
75
+ for t in threads:
78
76
  t.join()
79
- result.append(t.value)
80
- index += 1
77
+ result.append(t.result)
81
78
  if isinstance(array_or_tuple, tuple):
82
79
  return tuple(result)
83
80
  return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: functionalthreading
3
- Version: 0.4.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,6 @@
1
1
  [project]
2
2
  name = "functionalthreading"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  authors = [
5
5
  { name="Richard Tong", email="richytong@gmail.com" },
6
6
  ]
@@ -1,15 +0,0 @@
1
- from threading import Thread as _Thread
2
-
3
- class Thread(_Thread):
4
- def __init__(self, *args, **kwargs):
5
- _Thread.__init__(self, *args, **kwargs)
6
- self.value = None
7
- self.target = kwargs['target']
8
- self.args = kwargs['args']
9
-
10
- def run(self):
11
- self.value = self.target(*self.args)
12
-
13
- __name__ = 'classes'
14
-
15
- __all__ = ['Thread']