An easy to use tools module for writing multi-thread and multi-process programs.
Project description
QSpider
An easy to use tools module for writing multi-thread and multi-process programs.
Install
QSpider could be easily installed using pip:
$ pip install qspider
Example
import requests
from qspider 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]
Releases
- v0.1.1: First release with basic classes.
- v0.1.2: Reconstruct code, add ThreadManager, ProcessManager and other tool classes.
- v0.1.3: Fix multiprocess locking bug on Windows.
- v0.1.4:
- Add silent argument in manager._run method.
- Enhance the display style of the progress message.
- v0.1.5:
- Make task be either a class, a function or a class method.
- Add concurrent decorators for convenient use.
- Add concurrent decorator examples.
- v0.1.6:
- Update templates.
- Replace multiprocessing queue.
- Support with statement.
- Optimize displays in jupyter notebook and windows powershell.
License
Copyright (c) 2020 tishacy.
Licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qspider-0.1.6.tar.gz
(11.4 kB
view details)
Built Distribution
qspider-0.1.6-py3-none-any.whl
(17.1 kB
view details)
File details
Details for the file qspider-0.1.6.tar.gz
.
File metadata
- Download URL: qspider-0.1.6.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9230627b776611b3df3fd10f686ebcfea10a72afc9f8c3de416902a43a4a1f55 |
|
MD5 | ef3de1ddeeb0bbf4b30efe207a3e592b |
|
BLAKE2b-256 | 74d123e9b3f81801faa1e5a42a69c6412e77aea2e14b0e4065b6455c1fec4850 |
File details
Details for the file qspider-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: qspider-0.1.6-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8cfa04a0e7735f2d787d488487f4ce2cb626631829051eaaab5bacd9c6a4029 |
|
MD5 | 75c4449dac160bfa7033731dd4d93c3d |
|
BLAKE2b-256 | 8378f49536dcadfb68676d8db64f686a9e3717d072dd3e0fcc828d32b3a28c13 |