Skip to content

Commit c2e5cd3

Browse files
Merge pull request #13 from caffeine-addictt/doc-update-for-pre-release-of-v012
Doc update for pre release of v0.1.2
2 parents 50a18a8 + 8069e66 commit c2e5cd3

File tree

4 files changed

+69
-24
lines changed

4 files changed

+69
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ _Below is an example of how you can instruct your audience on installing and set
7575
2. Import thread into your library!
7676
```py
7777
import thread
78-
from thread import Thread, ...
78+
from thread import Thread, ParallelProcessing
7979
```
8080

8181
<p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -96,8 +96,8 @@ Our docs are [here!](/docs/getting-started.md)
9696

9797
- [x] Bug fixes
9898
- [x] Set Thread class to inherit from threading.Thread
99-
- [ ] Add kill method
100-
- [ ] Docs Update
99+
- [x] Add kill method
100+
- [x] Docs Update
101101
- [ ] v0.1.2 Release
102102

103103
See the [open issues](https://github.com/caffeine-addictt/thread/issues) for a full list of proposed features (and known issues).

docs/getting-started.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ Here's to you get started.
88

99
## Prerequisites
1010

11-
* Python 3.11+
11+
* Python 3.9+
1212

13-
The project is quite heavily type-annotated, and we use `Concatenate[Any, ...]` in some function declarations.
14-
However `Python <=3.10` does not support `...` being the last argument as laid out in [this stack overflow question](https://stackoverflow.com/questions/74893354/is-literal-ellipsis-really-valid-as-paramspec-last-argument).
15-
16-
If possible, I may release a sister version of thread that is compatible with `Python 3.9+` in the future, but for the time being,
17-
support will extend only from Python 3.11+
1813

1914
<br />
2015

docs/parallel-processing.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ my_processor.start()
9494
9595
* **overflow_kwargs : Overflow_In
9696
> These are arguments parsed to [**thread.Thread**](./threading.md#parameters)<br />
97-
> [!NOTE]
97+
> [!NOTE]<br />
9898
> If `args` is present, then it will automatically be removed from kwargs and joined with `overflow_args`
9999
100100
* **Raises** AssertionError: max_threads is invalid
@@ -107,9 +107,9 @@ my_processor.start()
107107
These are attributes of [`ParallelProcessing`](#importing-the-class) class
108108

109109
* results : List[Data_Out]
110-
> The result value
111-
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
112-
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)
110+
> The result value<br />
111+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)<br />
112+
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)<br />
113113
> **Raises** [`ThreadStillRunningError`](./exceptions.md#threadStillRunningError)
114114
115115
<br />
@@ -131,10 +131,18 @@ These are methods of [`ParallelProcessing`](#importing-the-class) class
131131
> Halts the current thread execution until the thread completes
132132
133133
* join : () -> JoinTerminatedStatus
134-
> Halts the current thread execution until a thread completes or exceeds the timeout
135-
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
134+
> Halts the current thread execution until a thread completes or exceeds the timeout<br />
135+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)<br />
136136
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)
137137
138+
* kill : (yielding: bool = False, timeout: float = 5) -> bool
139+
> Schedules the thread to be killed<br />
140+
> If yielding is True, it halts the current thread execution until the thread is killed or the timeout is exceeded<br />
141+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadnotinitializederror)<br />
142+
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)<br />
143+
> [!NOTE]<br />
144+
> This only schedules the thread to be killed, and does not immediately kill the thread
145+
138146
<br />
139147

140148

docs/threading.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ I will lay out how to use the `thread.Thread` class!
1111
<li><a href='#parameters'> Parameters </a></li>
1212
<li><a href='#attributes'> Attributes </a></li>
1313
<li><a href='#methods'> Class Methods </a></li>
14+
<li><a href='#behviours'> Behaviours </a></li>
1415
</ul>
1516
</details>
1617

@@ -49,9 +50,6 @@ A thread can be ran by invoking the `start()` method
4950
my_thread.start()
5051
```
5152

52-
> [!NOTE]
53-
> The **threading.Thread()** class from python will only be initialized when **start()** is invoked
54-
5553
<br />
5654

5755

@@ -83,6 +81,11 @@ my_thread.start()
8381
* daemon : bool = False
8482
> This is an argument parsed to `threading.Thread`
8583
84+
* group : None = None
85+
> This is an argument parsed to `threading.Thread`<br />
86+
> [!NOTE]<br />
87+
> This does nothing
88+
8689
* *overflow_args : Overflow_In
8790
> These are arguments parsed to `threading.Thread`
8891
@@ -98,10 +101,13 @@ These are attributes of [`Thread`](#importing-the-class) class
98101

99102
* result : Data_Out
100103
> The result value of the thread
101-
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
102-
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)
104+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)<br />
105+
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)<br />
103106
> **Raises** [`ThreadStillRunningError`](./exceptions.md#threadStillRunningError)
104107
108+
* status : str
109+
> The current status of the thread
110+
105111
<br />
106112

107113

@@ -118,18 +124,54 @@ These are methods of [`Thread`](#importing-the-class) class
118124
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
119125
120126
* add_hook : ((Data_Out) -> Any | None) -> None
121-
> Hooks will be automatically invoked after a thread successfully completes, parsing the return value as the first argument
122-
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
127+
> Hooks will be automatically invoked after a thread successfully completes, parsing the return value as the first argument<br />
128+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)<br />
123129
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)
124130
125131
* get_return_value : () -> Data_Out
126132
> Halts the current thread execution until the thread completes
127133
128134
* join : () -> JoinTerminatedStatus
129-
> Halts the current thread execution until a thread completes or exceeds the timeout
130-
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)
135+
> Halts the current thread execution until a thread completes or exceeds the timeout<br />
136+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadNotInitializedError)<br />
131137
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)
132138
139+
* kill : (yielding: bool = False, timeout: float = 5) -> bool
140+
> Schedules the thread to be killed<br />
141+
> If yielding is True, it halts the current thread execution until the thread is killed or the timeout is exceeded<br />
142+
> **Raises** [`ThreadNotInitializedError`](./exceptions.md#threadnotinitializederror)<br />
143+
> **Raises** [`ThreadNotRunningError`](./exceptions.md#threadnotrunningerror)<br />
144+
> [!NOTE]<br />
145+
> This only schedules the thread to be killed, and does not immediately kill the thread
146+
147+
<br />
148+
149+
150+
## Behviours
151+
152+
These are a list of thread behvaiours
153+
154+
### Killing Threads - Introduced in v0.1.2
155+
156+
While preferably not utilized, we do support killing threads.<br />
157+
We mark a thread to be killed, and will only be killed when the thread invokes `sys.settrace()`.
158+
159+
> [!IMPORTANT]<br />
160+
> This means that if your `target` has a long `time.wait()` call, it will only be killed after it moves onto the next line.
161+
162+
<br />
163+
164+
Want an alternative? Learn about [Daemonized Threads!](https://www.geeksforgeeks.org/python-daemon-threads/)
165+
166+
<br />
167+
168+
169+
### Gracefull Exiting - Introduced in v0.1.2
170+
171+
When the program is abruptly stopped with `CTRL+C` for example, active threads will now attempt to gracefully kill itself.<br />
172+
173+
This is not to be an "end-all be-all" for managing threads. You should still try to properly exit a thread before abruptly exiting the program, or utilize a `Daemonized Thread`.
174+
133175
<br />
134176

135177

0 commit comments

Comments
 (0)