Skip to main content

Very easy multithreading

Project description

meanwhile - Very Easy Multithreading

This module is useful when you want to apply the same function to many values, and you want to do it in many threads. It's useful when the function requires I/O operations, like file access or HTTP(S) queries.

Installation

pip3 install meanwhile

Simple Usage Example

Assume you have a function named test_url, that gets a URL, downloads its content, and tests whether it contains the word "meanwhile". Also, assume you have a file, named urls.txt, where each line contains a URL you would like to apply test_url to.

You can do the following:

>>> from meanwhile import Job
>>> job = Job(test_url, 10)    # 10 threads will be used.
>>> urls = open("urls.txt").read().splitlines()
>>> job.add_many(urls)
>>> job.wait()
>>> results = job.get_results()

Note that the function you apply to each input must get one argument, and that this argument must be hashable.

Note that if your function prints output, you probably want to use meanwhile.print() instead of the built-in print() function.

Advanced Features

The module supports many useful features. For example, you can:

  • Get progress info;
  • Change the number of threads used;
  • Pause and resume all threads;
  • Add new inputs, when the job is already in progress, or even finished;
  • Inspect exceptions raised by inputs;
  • Replace the target function;
  • Automatically or manually retry inputs that caused exceptions.

For full documentation, see help(meanwhile.Job).

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

meanwhile-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file meanwhile-1.0.1.tar.gz.

File metadata

  • Download URL: meanwhile-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.8

File hashes

Hashes for meanwhile-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2cdf575c764db33159d43fe616d31b119c0df52ae8687b34d00747210f329885
MD5 8792a6295992d1d9dc03cb5d97ee9773
BLAKE2b-256 176cb7210410aa0e4e50239d287ae8462c4d337d44954a99823e00fef8b92f97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page