Skip to main content

Add python code in threading mode

Project description

threadmycode is a tiny Python library lets you convert your Python methods into asynchronous, non-blocking methods simply by using a decorator.

To enable the theading mode, First paramater should not be keyword paramater First paramater of the function must be iterable Function will be called in thread with first paramter as iterated value of iterable

if first paramater is not a iterable then normal execution happens

Example

    # example.py
    import threadmycode as multithreading
    import time
    import random
    import signal
    # kill all tasks on ctrl-c
    # signal.signal(signal.SIGINT, multithreading.killall)

    # or, wait for task to finish on ctrl-c:
    signal.signal(signal.SIGINT, multithreading.stop)

    @multithreading.threadit
    def hello(count):
        sleep = 3
        print("Hello %s (sleeping for %ss)" % (count, sleep))
        time.sleep(3)
        print("Goodbye %s (after for %ss)" % (count, sleep))

    if __name__ == "__main__":
            multithreading.threadCount(5)
            hello(range(10))

The output would look something like this:

    $ python example.py
    
    Hello 0 (sleeping for 3s)
    Hello 1 (sleeping for 3s)
    Hello 2 (sleeping for 3s)
    Hello 3 (sleeping for 3s)
    Goodbye 0 (after for 3s)
    Goodbye 1 (after for 3s)
    Goodbye 2 (after for 3s)
    Goodbye 3 (after for 3s)
    Hello 4 (sleeping for 3s)
    Hello 5 (sleeping for 3s)
    Hello 6 (sleeping for 3s)
    Hello 7 (sleeping for 3s)
    Goodbye 4 (after for 3s)
    Goodbye 5 (after for 3s)
    Hello 8 (sleeping for 3s)
    Goodbye 6 (after for 3s)
    Hello 9 (sleeping for 3s)
    Goodbye 7 (after for 3s)
    Goodbye 8 (after for 3s)
    Goodbye 9 (after for 3s)

Settings

The default maximum threads is equal to the # of CPU Cores. This is just a rule of thumb! The Thread module isn't actually using more than one core at a time.

You can change the default maximum number of threads using:

    import threadmycode as multithreading
    multithreading.threadCount(10)

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

threadmycode-0.0.7.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

threadmycode-0.0.7-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file threadmycode-0.0.7.tar.gz.

File metadata

  • Download URL: threadmycode-0.0.7.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.1

File hashes

Hashes for threadmycode-0.0.7.tar.gz
Algorithm Hash digest
SHA256 1c48963e235e5a78918d9225379e004099b9be45dd5ad0f5d1ac817e1d36e6a0
MD5 dffceb32f4f7332f4fa58e578c2caa87
BLAKE2b-256 64fac079944fe0a159b60bdfe74f70977e4f35ad465e9a97d78de51c5370f861

See more details on using hashes here.

File details

Details for the file threadmycode-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: threadmycode-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.1

File hashes

Hashes for threadmycode-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6e75df2da75a7c8136624c7c9fe486cae27542041d1a3616455efdf72c00bf9d
MD5 8775a14125bccba36c1b6df4a9701968
BLAKE2b-256 c9dd5345be966c35d5bea0740ce8beddacd9ea014897c7c9b2da851faf66f5e9

See more details on using hashes here.

Supported by

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