Skip to content

Commit b33ff57

Browse files
committed
Reformat newlines & code in ThreadWithResult docstring
1 parent 90e4f6b commit b33ff57

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

python/save_thread_result/__init__.py

+14-30
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ class ThreadWithResult(threading.Thread):
2424
The `threading.Thread` subclass ThreadWithResult saves the result of a thread
2525
as its `result` attribute - i.e. call `thread_with_result_instance_1.result`
2626
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(
3029
target = my_function,
3130
args = (my_function_arg1, my_function_arg2, ...)
3231
kwargs = {my_function_kwarg1: kwarg1_value, my_function_kwarg2: kwarg2_value, ...}
3332
)
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!
4036
4137
4238
NOTE: As of Release 0.0.3, you can also specify values for
@@ -48,31 +44,24 @@ class ThreadWithResult(threading.Thread):
4844
from the python interpreter with:
4945
help(ThreadWithResult)
5046
51-
OVERVIEW:
5247
48+
OVERVIEW:
5349
ThreadWithResult is a `threading.Thread` subclass used to save the
5450
result of a function called through the threading interface, since
55-
56-
thread = threading.Thread(
51+
>>> thread = threading.Thread(
5752
target = my_function,
5853
args = (my_function_arg1, my_function_arg2, ...)
5954
kwargs = {my_function_kwarg1: kwarg1_value, my_function_kwarg2: kwarg2_value, ...}
6055
)
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!
6959
executes and returns immediately after the thread finishes,
7060
WITHOUT providing any way to get the return value
7161
from the function that ran on that thread.
7262
7363
7464
USAGE:
75-
7665
The name of the function to run on a separate thread should
7766
be passed to `ThreadWithResult` through the `target` argument,
7867
and any arguments for the function should be passed in
@@ -84,7 +73,6 @@ class ThreadWithResult(threading.Thread):
8473
8574
8675
EXPLANATION:
87-
8876
We create a closure function to run the actual function we want
8977
to run on a separate thread, enclose the function passed to
9078
`target` - along with the arguments provided to `args` and `kwargs` -
@@ -119,14 +107,12 @@ class ThreadWithResult(threading.Thread):
119107
If you want to mute logging this message to the terminal for all
120108
ThreadWithResult instances, set the
121109
`log_thread_status` class attribute to False:
122-
123-
ThreadWithResult.log_thread_status = False
110+
>>> ThreadWithResult.log_thread_status = False
124111
125112
If you only want to mute logging this message to the terminal for
126113
a specific instance of ThreadWithResult, set the
127114
`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
130116
131117
Keep in mind python prioritizes the `log_thread_status` instance attribute
132118
over the `log_thread_status` class attribute!
@@ -136,16 +122,14 @@ class ThreadWithResult(threading.Thread):
136122
for all ThreadWithResult instances, set the
137123
`log_files` class attribute to an iterable object contatining
138124
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]
141126
142127
143128
If you only want to log this message to an output file (or multiple output files)
144129
for a specific instance of ThreadWithResult, set the
145130
`log_files` attribute for the specific instance to an iterable
146131
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]
149133
150134
Keep in mind python prioritizes the `log_files` instance attribute
151135
over the `log_files` class attribute!

0 commit comments

Comments
 (0)