@@ -24,19 +24,15 @@ class ThreadWithResult(threading.Thread):
24
24
The `threading.Thread` subclass ThreadWithResult saves the result of a thread
25
25
as its `result` attribute - i.e. call `thread_with_result_instance_1.result`
26
26
after `thread_with_result_instance_1` finishes running to get the return
27
- value from the function that ran on that thread.
28
-
29
- thread = ThreadWithResult(
27
+ value from the function that ran on that thread:
28
+ >>> thread = ThreadWithResult(
30
29
target = my_function,
31
30
args = (my_function_arg1, my_function_arg2, ...)
32
31
kwargs = {my_function_kwarg1: kwarg1_value, my_function_kwarg2: kwarg2_value, ...}
33
32
)
34
-
35
- thread.start()
36
-
37
- thread.join()
38
-
39
- thread.result # returns value returned from function passed in to the `target` argument!
33
+ >>> thread.start()
34
+ >>> thread.join()
35
+ >>> thread.result # returns value returned from function passed in to the `target` argument!
40
36
41
37
42
38
NOTE: As of Release 0.0.3, you can also specify values for
@@ -48,31 +44,24 @@ class ThreadWithResult(threading.Thread):
48
44
from the python interpreter with:
49
45
help(ThreadWithResult)
50
46
51
- OVERVIEW:
52
47
48
+ OVERVIEW:
53
49
ThreadWithResult is a `threading.Thread` subclass used to save the
54
50
result of a function called through the threading interface, since
55
-
56
- thread = threading.Thread(
51
+ >>> thread = threading.Thread(
57
52
target = my_function,
58
53
args = (my_function_arg1, my_function_arg2, ...)
59
54
kwargs = {my_function_kwarg1: kwarg1_value, my_function_kwarg2: kwarg2_value, ...}
60
55
)
61
-
62
- thread.start()
63
-
64
- thread.join()
65
-
66
- thread.result # does not work!
67
-
68
-
56
+ >>> thread.start()
57
+ >>> thread.join()
58
+ >>> thread.result # does not work!
69
59
executes and returns immediately after the thread finishes,
70
60
WITHOUT providing any way to get the return value
71
61
from the function that ran on that thread.
72
62
73
63
74
64
USAGE:
75
-
76
65
The name of the function to run on a separate thread should
77
66
be passed to `ThreadWithResult` through the `target` argument,
78
67
and any arguments for the function should be passed in
@@ -84,7 +73,6 @@ class ThreadWithResult(threading.Thread):
84
73
85
74
86
75
EXPLANATION:
87
-
88
76
We create a closure function to run the actual function we want
89
77
to run on a separate thread, enclose the function passed to
90
78
`target` - along with the arguments provided to `args` and `kwargs` -
@@ -119,14 +107,12 @@ class ThreadWithResult(threading.Thread):
119
107
If you want to mute logging this message to the terminal for all
120
108
ThreadWithResult instances, set the
121
109
`log_thread_status` class attribute to False:
122
-
123
- ThreadWithResult.log_thread_status = False
110
+ >>> ThreadWithResult.log_thread_status = False
124
111
125
112
If you only want to mute logging this message to the terminal for
126
113
a specific instance of ThreadWithResult, set the
127
114
`log_thread_status` attribute for the specific instance to False:
128
-
129
- thread_with_result_instance.log_thread_status = False
115
+ >>> thread_with_result_instance.log_thread_status = False
130
116
131
117
Keep in mind python prioritizes the `log_thread_status` instance attribute
132
118
over the `log_thread_status` class attribute!
@@ -136,16 +122,14 @@ class ThreadWithResult(threading.Thread):
136
122
for all ThreadWithResult instances, set the
137
123
`log_files` class attribute to an iterable object contatining
138
124
objects that support the .write() method:
139
-
140
- ThreadWithResult.log_files = [file_object_1, file_object_2]
125
+ >>> ThreadWithResult.log_files = [file_object_1, file_object_2]
141
126
142
127
143
128
If you only want to log this message to an output file (or multiple output files)
144
129
for a specific instance of ThreadWithResult, set the
145
130
`log_files` attribute for the specific instance to an iterable
146
131
object contatining objects that support the .write() method:
147
-
148
- thread_with_result_instance.log_files = [file_object_1, file_object_2]
132
+ >>> thread_with_result_instance.log_files = [file_object_1, file_object_2]
149
133
150
134
Keep in mind python prioritizes the `log_files` instance attribute
151
135
over the `log_files` class attribute!
0 commit comments