<commit_before>import threading
import time

from Cocoa import NSAutoreleasePool
from Cocoa import NSThread

__all__ = ["enter_autorelease_pool",
           "exit_autorelease_pool",
           "autorelease"]


## Pool directory & lock.

_autorelease_pool_lock = threading.Lock()
_autorelease_pools = {}


## Utility.

def _create_pool():
    return NSAutoreleasePool.alloc().init()


## Non-context manager API.

def enter_autorelease_pool():
    _autorelease_pool_lock.acquire()
    thread = NSThread.currentThread()
    if thread not in _autorelease_pools:
        _autorelease_pools[thread] = []
    pool_stack = _autorelease_pools[thread]
    pool_stack.append(_create_pool())
    _autorelease_pool_lock.release()

def exit_autorelease_pool():
    _autorelease_pool_lock.acquire()
    thread = NSThread.currentThread()
    pool_stack = _autorelease_pools[thread]
    pool = pool_stack.pop()
    del pool
    _autorelease_pool_lock.release()


## Context manager API.

class _AutoreleasePoolContextManager(object):
    def __enter__(self):
        enter_autorelease_pool()
    def __exit__(self, type, value, traceback):
        exit_autorelease_pool()

autorelease = _AutoreleasePoolContextManager()


## Cleaning thread.

def _clean_autorelease_pools():
    _autorelease_pool_lock.acquire()
    for thread in list(_autorelease_pools):
        if thread.isFinished():
            del _autorelease_pools[thread]
        else:
            pool_stack = _autorelease_pools[thread]
            for idx, pool in enumerate(pool_stack):
                pool_stack[idx] = create_pool()
                del pool
    _autorelease_pool_lock.release()

def _cleaner():
    while True:
        _clean_autorelease_pools()
        time.sleep(1.0)

_cleaner = threading.Thread(target=_cleaner)
_cleaner.daemon = True
_cleaner.start()<commit_msg>add missing underscore<commit_after>import threading
import time

from Cocoa import NSAutoreleasePool
from Cocoa import NSThread

__all__ = ["enter_autorelease_pool",
           "exit_autorelease_pool",
           "autorelease"]


## Pool directory & lock.

_autorelease_pool_lock = threading.Lock()
_autorelease_pools = {}


## Utility.

def _create_pool():
    return NSAutoreleasePool.alloc().init()


## Non-context manager API.

def enter_autorelease_pool():
    _autorelease_pool_lock.acquire()
    thread = NSThread.currentThread()
    if thread not in _autorelease_pools:
        _autorelease_pools[thread] = []
    pool_stack = _autorelease_pools[thread]
    pool_stack.append(_create_pool())
    _autorelease_pool_lock.release()

def exit_autorelease_pool():
    _autorelease_pool_lock.acquire()
    thread = NSThread.currentThread()
    pool_stack = _autorelease_pools[thread]
    pool = pool_stack.pop()
    del pool
    _autorelease_pool_lock.release()


## Context manager API.

class _AutoreleasePoolContextManager(object):
    def __enter__(self):
        enter_autorelease_pool()
    def __exit__(self, type, value, traceback):
        exit_autorelease_pool()

autorelease = _AutoreleasePoolContextManager()


## Cleaning thread.

def _clean_autorelease_pools():
    _autorelease_pool_lock.acquire()
    for thread in list(_autorelease_pools):
        if thread.isFinished():
            del _autorelease_pools[thread]
        else:
            pool_stack = _autorelease_pools[thread]
            for idx, pool in enumerate(pool_stack):
                pool_stack[idx] = _create_pool()
                del pool
    _autorelease_pool_lock.release()

def _cleaner():
    while True:
        _clean_autorelease_pools()
        time.sleep(1.0)

_cleaner = threading.Thread(target=_cleaner)
_cleaner.daemon = True
_cleaner.start()
{'fraction_non_alphanumeric': 0.08927599346761024, 'fraction_numerical': 0.0010887316276537834, 'mean_word_length': 3.588014981273408, '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': '1181047', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1190, 'n_words': 221}