Skip to content

Commit 0101c8d

Browse files
committed
pre-publish
1 parent d759d7b commit 0101c8d

File tree

9 files changed

+689
-96
lines changed

9 files changed

+689
-96
lines changed

README.Rmd

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
title: '`ezpq`: an easy parallel queueing system.'
32
output:
4-
github_document:
3+
md_document:
54
toc: true
65
toc_depth: 3
6+
variant: markdown_strict+backtick_code_blocks
7+
pandoc_args: ["--atx-headers"]
78
---
89

910
```{r setup, include=FALSE}
@@ -26,6 +27,8 @@ if os.path.exists('./ezpq/__init__.py') and sys.path[0] != os.getcwd():
2627
import ezpq
2728
```
2829

30+
# `ezpq`: an easy parallel queueing system.
31+
2932
Read this on [GitHub](https://github.com/dm3ll3n/ezpq) or [my site](https://www.donaldmellenbruch.com/project/ezpq/).
3033

3134
## Overview
@@ -98,17 +101,13 @@ print('> Runtime: ' + str(end - start))
98101
```
99102

100103
Here is the function ran in parallel with an `ezpq` Queue of 6 workers. Thus, the runtime of the above operation will be reduced from ~60s to ~10s.
101-
102-
```{python, echo=TRUE}
104+
105+
```{python, eval=FALSE, echo=TRUE}
103106
start = time.time()
104-
```
105107
106-
```{python, echo=TRUE}
107108
with ezpq.Queue(6) as Q:
108109
output = Q.map(random_sleep, range(60))
109-
```
110110
111-
```{python, echo=TRUE}
112111
end = time.time()
113112
print('> Runtime: ' + str(end - start))
114113
```
@@ -170,19 +169,21 @@ plt.save('docs/imgs/quickstart.png')
170169

171170
![](docs/imgs/quickstart.png)
172171

173-
## `ezpq.Queue`
172+
## ezpq.Queue
174173

175174
The `Queue` class implements the queueing system, which is itself a 3-part system composed of the:
176175

176+
177177
1. waiting queue
178178
2. working table
179179
3. completed queue
180180

181+
181182
```{python}
182183
print(help(ezpq.Queue.__init__))
183184
```
184185

185-
## `ezpq.Job`
186+
## ezpq.Job
186187

187188
A `ezpq` job defines the function to run. It is passed to an `ezpq` queue with a call to `submit()`.
188189

@@ -209,7 +210,7 @@ plt.save('docs/imgs/submit.png')
209210
![](docs/imgs/submit.png)
210211

211212

212-
### `put`
213+
### put
213214

214215
The `put` method creates a job and submits it to an `ezpq` queue. All of its arguments are passed to `ezpq.Job()`.
215216

@@ -221,7 +222,7 @@ with ezpq.Queue(6) as Q:
221222
output = Q.collect()
222223
```
223224

224-
### `size`
225+
### size
225226

226227
`size()` returns a count of all items across all three queue components. It accepts three boolean parameters, `waiting`, `working`, and `completed`. If all of these are `False` (default), all jobs are counted. If any combination of these is `True`, only the corresponding queue(s) will be counted. For example:
227228

@@ -250,7 +251,7 @@ with ezpq.Queue(6) as Q:
250251
print_sizes(Q)
251252
```
252253

253-
### `wait`
254+
### wait
254255

255256
The `wait()` method will block execution until all jobs complete. It also accepts a `timeout` parameter, given in seconds. The return value is the count of jobs that did not complete. Thus, a return value greater than 0 indicates the timeout was exceeded. The parameter `poll` can be used to adjust how frequently (in seconds) the operation checks for completed jobs (default=0.1).
256257

@@ -259,7 +260,7 @@ New in v0.2.0, include `show_progress=True` to show a progress bar while waiting
259260
![](docs/imgs/tqdm.gif)
260261

261262

262-
### `get`
263+
### get
263264

264265
`get()` retrieves and deletes ("pop") the highest priority job from the completed queue, if one is available. If the completed queue is empty, `get()` returns `None`. However, `get()` will wait for a completed job if the `poll` frequency is greater than 0. If the timeout is exceeded, `None` is returned.
265266

@@ -271,12 +272,12 @@ with ezpq.Queue(6) as Q:
271272
for x in range(n_inputs):
272273
Q.put(random_sleep, args=x)
273274
274-
# repeatedly `get()` queue is empty.
275+
# repeatedly `get()` until queue is empty.
275276
for i in range(n_inputs):
276277
output[i] = Q.get(poll=0.1)
277278
```
278279

279-
### `collect`
280+
### collect
280281

281282
`collect()` is similar to `get()`, but it will return a list of *all* completed jobs and clear the completed queue. It does not support the `poll` or `timeout` parameters, but you can call `wait()` before `collect()` if desired.
282283

@@ -296,13 +297,13 @@ with ezpq.Queue(6) as Q:
296297
print('Output size: {0}'.format(len(output)))
297298
```
298299

299-
### `map`
300+
### map
300301

301302
`map` encapsulates the logic of `put`, `wait`, and `collect` in one call. Include `show_progress=True` to get output `tqdm` progress bar.
302303

303304
![](docs/imgs/tqdm_map.gif)
304305

305-
### `dispose`
306+
### dispose
306307

307308
The queueing operations performed by `ezpq.Queue` are performed on a periodic basis. By default, the `poll` parameter for a Queue is `0.1` seconds. This "pulse" thread will continue firing until the Queue is disposed of.
308309

@@ -325,7 +326,7 @@ When you have jobs that are dependent upon another, you can use "lanes" to execu
325326

326327
In the above graphic, notice how same-colored bars never overlap. These bars represent jobs that are in the same lane, which executed synchronously.
327328

328-
## `ezpq.Plot`
329+
## ezpq.Plot
329330

330331
The `Plot` class is used to visualize the wait, start, and end times for each job that entered the queueing system. The class is initialized with a list of dicts; exactly what is returned from a call to `collect()` or `map()`.
331332

0 commit comments

Comments
 (0)