Git Product home page Git Product logo

qspider's Introduction

QSpider

License: MIT Pyversion Version

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.

qspider's People

Contributors

tishacy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.