<commit_before>
[![pythonversions](https://img.shields.io/pypi/pyversions/timekiller.svg)](https://pypi.python.org/pypi/timekiller)
[![License](https://img.shields.io/pypi/l/timekiller.svg)](https://opensource.org/licenses/MIT)

# Timekiller
It lets call any function with a timeout!

## Install

```bash
pip install timekiller
```

Link pypi: https://pypi.python.org/pypi/timekiller

## Example

## Call function
```python
import timekiller
import time


def long_function(foo, bar):
    while True:
        time.sleep(10)
        print(foo, bar)

# call(func, max_time, *args, **kwargs)
timekiller.call(long_function, 5, "woo", bar="Uhmm")


@timekiller.timeout(5)
def long_function_with_decorator(foo, bar)
    while True:
        time.sleep(10)
        print(foo, bar)

long_function_with_decorator("woo", "Uhmm")
```

## Capture exception

```python
import timekiller
import time


@timeout(1)
def long_function():
    try:
        time.sleep(10)
    except timekiller.TimeoutException:
        print("capture exception")

long_function()
```
TODO:
 - It works in main thread and processes (not work in threads)<commit_msg>modified examples for a better understanding<commit_after>
[![pythonversions](https://img.shields.io/pypi/pyversions/timekiller.svg)](https://pypi.python.org/pypi/timekiller)
[![License](https://img.shields.io/pypi/l/timekiller.svg)](https://opensource.org/licenses/MIT)

# Timekiller
It lets call any function with a timeout!

## Install

```bash
pip install timekiller
```

Link pypi: https://pypi.python.org/pypi/timekiller

## Example

## Call function
```python
from timekiller import timeout, call
import time


def long_function(foo, bar):
    while True:
        time.sleep(10)
        print(foo, bar)

# call(func, max_time, *args, **kwargs)
call(long_function, 5, "woo", bar="Uhmm")


@timeout(5)
def long_function_with_decorator(foo, bar)
    while True:
        time.sleep(10)
        print(foo, bar)

long_function_with_decorator("woo", "Uhmm")
```

## Capture exception

```python
from timekiller import timeout, TimeoutException
import time


@timeout(1)
def long_function():
    try:
        time.sleep(10)
    except TimeoutException:
        print("capture exception")

long_function()
```
TODO:
 - It works in main thread and processes (not work in threads)
{'fraction_non_alphanumeric': 0.1401909722222222, 'fraction_numerical': 0.0078125, 'mean_word_length': 4.2505694760820045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '4241611', 'n_tokens_mistral': 831, 'n_tokens_neox': 773, 'n_words': 178}