<commit_before>'''
Created on 18/04/2011

@author: mikel
'''
import threading
import types


class synchronized(object):
    _func = None
    _lock = threading.RLock()
    
    
    def __init__(self, func):
        self._func = func
    
    
    def __call__(self, *args, **kwargs):
        self._lock.acquire()
        
        try:
            result = self._func(*args, **kwargs)
        finally:
            self._lock.release()
        
        return result
    
    
    def __get__(self, obj, ownerClass=None):
        return types.MethodType(self, obj)
    
    
    @staticmethod
    def get_lock():
        return synchronized._lock
        <commit_msg>spotify: utils: decorators: added run_in_thread decorator.<commit_after>'''
Created on 18/04/2011

@author: mikel
'''
import threading
import types
import threads


class synchronized(object):
    _func = None
    _lock = threading.RLock()
    
    
    def __init__(self, func):
        self._func = func
    
    
    def __call__(self, *args, **kwargs):
        self._lock.acquire()
        
        try:
            result = self._func(*args, **kwargs)
        finally:
            self._lock.release()
        
        return result
    
    
    def __get__(self, obj, ownerClass=None):
        return types.MethodType(self, obj)
    
    
    @staticmethod
    def get_lock():
        return synchronized._lock



def run_in_thread(func=None, threads_per_class=10, single_instance=False):
    if callable(func):
        decorator = run_in_thread()
        return decorator(func)
    
    class decorator_class(object):
        __func = None
        
        
        def __init__(self, func):
            self.__func = func
        
        
        def __call__(self, *args, **kwargs):
            tm = threads.TaskManager(threads_per_class, single_instance)
            tm.add(self.__func, *args, **kwargs)
        
        
        def __get__(self, obj, type=None):
            return self.__class__(self.__func.__get__(obj, type))
    
    return decorator_class

{'fraction_non_alphanumeric': 0.09443665264142123, 'fraction_numerical': 0.008415147265077139, 'mean_word_length': 1.6716604244694133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2624039', 'n_tokens_mistral': 684, 'n_tokens_neox': 614, 'n_words': 137}