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.0.tar.gz (5.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: meanwhile-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 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.0.tar.gz
Algorithm Hash digest
SHA256 bf8af332fdc217c943b992eacf389d4c641f6c6c99bc57a13eda4c82d697e03e
MD5 c852ff9903d57443eeebe44d9aadd54d
BLAKE2b-256 077a39936b93b9478bc68959737b97fbb105b6325a1083df7846ac0adc03b457

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