<commit_before>   # -*- coding:utf-8 -*-
#-----------------------------------------------------------------------------
#  Copyright (c) 2015, ROOT Team.
#  Authors: <NAME>
#           <NAME> <<EMAIL>> http://oproject.org
#  Distributed under the terms of the Modified LGPLv3 License.
#
#  The full license is in the file COPYING.rst, distributed with this software.
#-----------------------------------------------------------------------------
from ctypes import CDLL, c_char_p
from threading import Thread
from time import sleep as timeSleep
from resource import setrlimit, RLIMIT_STACK, RLIM_INFINITY

_lib = CDLL("libJupyROOT.so")

class IOHandler(object):
    r'''Class used to capture output from C/C++ libraries.
    >>> import sys
    >>> h = IOHandler()
    >>> h.GetStdout()
    ''
    >>> h.GetStderr()
    ''
    >>> h.GetStreamsDicts()
    (None, None)
    >>> del h
    '''
    def __init__(self):
        for cfunc in [_lib.JupyROOTExecutorHandler_GetStdout,
                      _lib.JupyROOTExecutorHandler_GetStderr]:
           cfunc.restype = c_char_p
        _lib.JupyROOTExecutorHandler_Ctor()

    def __del__(self):
        _lib.JupyROOTExecutorHandler_Dtor()

    def Clear(self):
        _lib.JupyROOTExecutorHandler_Clear()

    def Poll(self):
        _lib.JupyROOTExecutorHandler_Poll()

    def InitCapture(self):
        _lib.JupyROOTExecutorHandler_InitCapture()

    def EndCapture(self):
        _lib.JupyROOTExecutorHandler_EndCapture()

    def GetStdout(self):
       return _lib.JupyROOTExecutorHandler_GetStdout()

    def GetStderr(self):
       return _lib.JupyROOTExecutorHandler_GetStderr()

    def GetStreamsDicts(self):
       out = self.GetStdout()
       err = self.GetStderr()
       outDict = {'name': 'stdout', 'text': out} if out != "" else None
       errDict = {'name': 'stderr', 'text': err} if err != "" else None
       return outDict,errDict

class Runner(object):
    ''' Asynchrously run functions
    >>> import time
    >>> def f(code):
    ...    print code
    >>> r= Runner(f)
    >>> r.Run("ss")
    ss
    >>> r.AsyncRun("ss");time.sleep(1)
    ss
    >>> def g(msg):
    ...    time.sleep(.5)
    ...    print msg
    >>> r= Runner(g)
    >>> r.AsyncRun("Asynchronous");print "Synchronous";time.sleep(1)
    Synchronous
    Asynchronous
    >>> r.AsyncRun("Asynchronous"); print r.HasFinished()
    False
    >>> time.sleep(1)
    Asynchronous
    >>> print r.HasFinished()
    True
    '''
    def __init__(self, function):
        self.function = function
        setrlimit(RLIMIT_STACK,(RLIM_INFINITY,RLIM_INFINITY))
        self.thread = None

    def Run(self, argument):
        return self.function(argument)

    def AsyncRun(self, argument):
        self.thread = Thread(target=self.Run, args =(argument,))
        self.thread.start()

    def Wait(self):
        if not self.thread: return
        self.thread.join()

    def HasFinished(self):
        if not self.thread: return True

        finished = not self.thread.is_alive()
        if not finished: return False
<commit_msg>Do not call setrlimit on osx<commit_after>   # -*- coding:utf-8 -*-
#-----------------------------------------------------------------------------
#  Copyright (c) 2015, ROOT Team.
#  Authors: <NAME>
#           <NAME> <<EMAIL>> http://oproject.org
#  Distributed under the terms of the Modified LGPLv3 License.
#
#  The full license is in the file COPYING.rst, distributed with this software.
#-----------------------------------------------------------------------------
from ctypes import CDLL, c_char_p
from threading import Thread
from time import sleep as timeSleep
from resource import setrlimit, RLIMIT_STACK, RLIM_INFINITY
from sys import platform

_lib = CDLL("libJupyROOT.so")

class IOHandler(object):
    r'''Class used to capture output from C/C++ libraries.
    >>> import sys
    >>> h = IOHandler()
    >>> h.GetStdout()
    ''
    >>> h.GetStderr()
    ''
    >>> h.GetStreamsDicts()
    (None, None)
    >>> del h
    '''
    def __init__(self):
        for cfunc in [_lib.JupyROOTExecutorHandler_GetStdout,
                      _lib.JupyROOTExecutorHandler_GetStderr]:
           cfunc.restype = c_char_p
        _lib.JupyROOTExecutorHandler_Ctor()

    def __del__(self):
        _lib.JupyROOTExecutorHandler_Dtor()

    def Clear(self):
        _lib.JupyROOTExecutorHandler_Clear()

    def Poll(self):
        _lib.JupyROOTExecutorHandler_Poll()

    def InitCapture(self):
        _lib.JupyROOTExecutorHandler_InitCapture()

    def EndCapture(self):
        _lib.JupyROOTExecutorHandler_EndCapture()

    def GetStdout(self):
       return _lib.JupyROOTExecutorHandler_GetStdout()

    def GetStderr(self):
       return _lib.JupyROOTExecutorHandler_GetStderr()

    def GetStreamsDicts(self):
       out = self.GetStdout()
       err = self.GetStderr()
       outDict = {'name': 'stdout', 'text': out} if out != "" else None
       errDict = {'name': 'stderr', 'text': err} if err != "" else None
       return outDict,errDict

class Runner(object):
    ''' Asynchrously run functions
    >>> import time
    >>> def f(code):
    ...    print code
    >>> r= Runner(f)
    >>> r.Run("ss")
    ss
    >>> r.AsyncRun("ss");time.sleep(1)
    ss
    >>> def g(msg):
    ...    time.sleep(.5)
    ...    print msg
    >>> r= Runner(g)
    >>> r.AsyncRun("Asynchronous");print "Synchronous";time.sleep(1)
    Synchronous
    Asynchronous
    >>> r.AsyncRun("Asynchronous"); print r.HasFinished()
    False
    >>> time.sleep(1)
    Asynchronous
    >>> print r.HasFinished()
    True
    '''
    def __init__(self, function):
        self.function = function
        if platform != 'darwin':
            setrlimit(RLIMIT_STACK,(RLIM_INFINITY,RLIM_INFINITY))
        self.thread = None

    def Run(self, argument):
        return self.function(argument)

    def AsyncRun(self, argument):
        self.thread = Thread(target=self.Run, args =(argument,))
        self.thread.start()

    def Wait(self):
        if not self.thread: return
        self.thread.join()

    def HasFinished(self):
        if not self.thread: return True

        finished = not self.thread.is_alive()
        if not finished: return False

{'fraction_non_alphanumeric': 0.16916626350588615, 'fraction_numerical': 0.0032252862441541686, 'mean_word_length': 2.2403343782654126, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 113, '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': '5546627', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1900, 'n_words': 444}