Async tools for Python
Async Tools for Python.
Threading is the most simple thing, but because of GIL it’s useless for computation. Only use when you want to parallelize the access to a blocking resource, e.g. network.
Decorator for functions that should be run in a separate thread. When the function is called, it returns a `threading.Event <https://docs.python.org/2/library/threading.html#event-objects>`__.
from asynctools.threading import Async @Async def request(url): # ... do request request('http://example.com') # Async request request('http://example.com').wait() # wait for it to complete
If you want to wait for multiple threads to complete, see next chapters.
Execute functions in parallel and collect results. Each function is executed in its own thread, all threads exit immediately.
from asynctools.threading import Parallel def request(url): # ... do request return data # Execute pll = Parallel(request) for url in links: pll(url) # Starts a new thread # Wait for the results results, errors = pll.join()
Since the request method takes just one argument, this can be chained:
results, errors = Parallel(request).map(links).join()
Create a pool of threads and execute work in it. Useful if you do want to launch a limited number of long-living threads.
Methods are same with `Parallel <#parallel>`__, with some additions:
from asynctools.threading import Pool def request(url): # ... do long request return data # Make pool pool = Pool(request, 5) # Assign some job for url in links: pll(url) # Runs in a pool # Wait for the results results, errors = pll.join()
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|asynctools-0.1.2_2-py2-none-any.whl (7.9 kB) Copy SHA256 Checksum SHA256||2.7||Wheel||Aug 14, 2014|
|asynctools-0.1.2-2.tar.gz (6.3 kB) Copy SHA256 Checksum SHA256||–||Source||Aug 14, 2014|