Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Provides simple interface for threading to easy perform async actions

Project description

py_easy_async provides simple interface for threading to easy perform async actions in Python versions 3.4 and up

Example of simple async operations

import py_easy_async
import time

def print_with_sleep(word):
    time.sleep(1)
    print(word)
    return 'done'

print('first')
easy_async.async(lambda: print_with_sleep('second'),
                 lambda done_string: print("done callback called with string: %s" % done_string))
print('third')

The above example will print the following:

first
third
second
done callback called with string: done

Example of thread pool management

from py_easy_async import pool

def message_handler(message):
    print('got message:', message)

identifier = pool.run_thread(message_handler, name='Persistent-Thread')

for i in range(5):
    pool.message(identifier, "test message #%s" % i)

pool.stop_thread(identifier)

The above example will start thread that will wait for messages that it should process:

Persistent-Thread starting...

got message: test message #0
got message: test message #1
got message: test message #2
got message: test message #3
got message: test message #4

Persistent-Thread exiting...

License

Released under the MIT license.

Installation

pip install py_easy_async

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for py_easy_async, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size py_easy_async-0.1.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page