<commit_before>AsyncTools
==========

Async Tools for Python.

Threading
---------

Threading is the most simple thing, but because of [GIL](https://wiki.python.org/moin/GlobalInterpreterLock) it's useless for computation.
Only use when you want to parallelize the access to a blocking resource, e.g. network.

## Parallel

Source: [asynctools/threading/Parallel.py](asynctools/threading/Parallel.py)

Execute functions in parallel and collect results.
Each function is executed in its own thread, all threads exit immediately.

Methods:

* `join()`: Wait for all tasks to be finished, and return two lists:
    
    * A list of results
    * A list of exceptions

Example:

```python
from asynctools.threading import Parallel

def request(url):
    # ... do request
    return data
   
# Execute
pll = Parallel(request)
for url in links:
    pll.job(url)  # Starts a new thread
    
    
# Wait for the results
results, errors = pll.join()
```

## Pool

Source: [asynctools/threading/Pool.py](asynctools/threading/Pool.py)

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:

* `join()`: Wait for all tasks to be finished and return `(results, errors)` (same as with [`Pool`](#pool))
* `close()`: Terminate all threads.
* `__enter__`, `__exit__` context manager to be used with `with` statement

Example:

```python
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.job(url)  # Runs in a pool

# Wait for the results
results, errors = pll.join()<commit_msg>README.md<commit_after>[![Build Status](https://api.travis-ci.org/kolypto/py-asynctools.png?branch=master)](https://travis-ci.org/kolypto/py-asynctools)


AsyncTools
==========

Async Tools for Python.

Table of Contents
=================

* <a href="#user-content-threading">Threading</a>
    * <a href="#user-content-parallel">Parallel</a>
    * <a href="#user-content-pool">Pool</a> 

Threading
=========

Threading is the most simple thing, but because of [GIL](https://wiki.python.org/moin/GlobalInterpreterLock) it's useless for computation.
Only use when you want to parallelize the access to a blocking resource, e.g. network.

Parallel
--------

Source: [asynctools/threading/Parallel.py](asynctools/threading/Parallel.py)

Execute functions in parallel and collect results.
Each function is executed in its own thread, all threads exit immediately.

Methods:

* `join()`: Wait for all tasks to be finished, and return two lists:
    
    * A list of results
    * A list of exceptions

Example:

```python
from asynctools.threading import Parallel

def request(url):
    # ... do request
    return data
   
# Execute
pll = Parallel(request)
for url in links:
    pll.job(url)  # Starts a new thread
    
    
# Wait for the results
results, errors = pll.join()
```



Pool
----

Source: [asynctools/threading/Pool.py](asynctools/threading/Pool.py)

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:

* `join()`: Wait for all tasks to be finished and return `(results, errors)` (same as with [`Pool`](#pool))
* `close()`: Terminate all threads.
* `__enter__`, `__exit__` context manager to be used with `with` statement

Example:

```python
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.job(url)  # Runs in a pool

# Wait for the results
results, errors = pll.join()
{'fraction_non_alphanumeric': 0.12237666939220496, 'fraction_numerical': 0.0005451076587626056, 'mean_word_length': 3.7538860103626943, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2783251', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1148, 'n_words': 416}