A tiny tool module for multi-process programs.
Project description
candypen
A tiny tool module for multi-process programs.
Install
candypen could be easily installed using pip:
$ pip install candypen
Example
import requests
from candypen import concurrent
# Define a source list for task function to parse.
def get_source():
"""Return a url list."""
return ['http://www.baidu.com' for i in range(500)]
# Define the task function and add a thread_func decorator
# The thread_func decorator needs a source list, and other options (num_workers, has_result ...) as arguments
@concurrent.thread_func(source=get_source(), num_workers=100, has_result=True)
def my_task(task_source):
"""A customized task function.
Process the task_source and return the processed results.
Arguments
:param task_source: the elem in the source list, which is a url here.
:rtype: (int) A http status code.
"""
url = task_source
res = requests.get(url, timeout=5)
return res.status_code
# Execute the task function.
results = my_task()
print(results)
Results of the example is as below:
[Info] 500 tasks in total.
[ ✔ ] 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 500/500 [eta-0:00:00, 0.9s, 542.9it/s]
[200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, ..., 200, 200, 200, 200]
License
Licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
candypen-0.0.1.tar.gz
(9.2 kB
view details)
Built Distribution
candypen-0.0.1-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file candypen-0.0.1.tar.gz
.
File metadata
- Download URL: candypen-0.0.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ef0b21df488249d3fbdfa6684fdcafa908513b1896566496ac96e236eee98c |
|
MD5 | 59b547875e0733eab8902599ca5f058c |
|
BLAKE2b-256 | 025b33e863e1c40b82904ac9046280972c1df514f74076dc8f7c1673d4e2083c |
File details
Details for the file candypen-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: candypen-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca2ab2f29fe776ac2fb02e5a7f080903981dc1e6d7a5333b0759d83fcc562e8 |
|
MD5 | 1d1b364cf0fd9d8e5732cac339f83c8c |
|
BLAKE2b-256 | 160a94363e172d13a219cb049197d87c9b5c6c7cd22aa0feb0c880d13e7755fc |