<commit_before>#!/usr/bin/python

#
# Careful with naming to deliberately allow this:
# from actor import *
#

from collections import deque as _deque
from functools import wraps as _wraps
import logging
import six
from six.moves import queue as _Queue
import sys
from threading import Thread as _Thread
import time
import sys

__all__ = ["Actor", "ActorMixin", "ActorMetaclass",
           "actor_method", "actor_function", "process_method",
           "late_bind", "UnboundActorMethod", "ActorException",
           "ActorNotStartedException",
           "late_bind_safe", "pipe", "wait_for", "stop", "pipeline",
           "wait_KeyboardInterrupt", "start"]


strace = False  #NOTE: Overview documented
trace_actor_calls = False

class UnboundActorMethod(Exception): #NOTE: Overview documented
    pass

class ActorNotStartedException(Exception): #NOTE: Overview documented
    pass


class ActorException(Exception):   #NOTE: Overview documented
    def __init__(self, *argv, **argd):
        super(ActorException, self).__init__(*argv)
        self.__dict__.update(argd)

def Print(*args):   #NOTE: Overview documented
    sys.stderr.write(" ".join([str(x) for x in args]))
    sys.stderr.write("\n")
    sys.stderr.flush()


class ActorMetaclass(type):   #NOTE: Overview documented
    def __new__(cls, clsname, bases, dct):
        new_dct = {}
        inboxes = {}
        outboxes = {}
        for name, val in dct.items():
            new_dct[name] = val
            if val.__class__ == tuple and len(val) == 3:
                tag, fn, arg = str(val[0]), val[1], val[2]
                if tag.startswith("ACTORFUNCTION"):
                    def mkcallback(func, __fcall_timeout=arg):
                        resultQueue = _Queue.Queue()
                        @_wraps(func)
                        def t(self, *args, **argd):
                            op = (func, self, args, argd)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION args", op)          # EXPERIMENTAL
                            self.F_inbound.append((op, resultQueue))
                            self._actor_notify()
                            #e, result = resultQueue.get(True, None)
                            try:
                                e, result = resultQueue.get(True, __fcall_timeout) # 5 seconds means pretty non-responsive.
                            except _Queue.Empty:
                                # The function call timed out. This could be a problem
                                # with the actor or it might not have been started. Check
                                # which and raise appropriately
                                if not self.is_alive():
                                    raise ActorNotStartedException
                                raise
                            if e:
                                six.reraise(*e)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION result", result)    # EXPERIMENTAL
                            return result
                        return t

                    new_dct[name] = mkcallback(fn,arg)

            if val.__class__ == tuple and len(val) == 2:
                tag, fn = str(val[0]), val[1]
                if tag.startswith("ACTORMETHOD"):
                    inboxes[fn.__name__] = fn.__doc__
                    def mkcallback(func):
                        @_wraps(func)
                        def t(self, *args, **argd):
                            if strace:                                            # EXPERIMENTAL
                                Print("strace:CALL ACTORMETHOD", func, args, argd)# EXPERIMENTAL
                            self.inbound.append((func, self, args, argd))
                            self._actor_notify()
                        return t
                    new_dct[name] = mkcallback(fn)

                elif tag.startswith("ACTORFUNCTION"):
                    def mkcallback(func):
                        resultQueue = _Queue.Queue()

                        @_wraps(func)
                        def t(self, __fcall_timeout=5, *args, **argd):
                            op = (func, self, args, argd)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION args", op)          # EXPERIMENTAL
                            self.F_inbound.append((op, resultQueue))
                            self._actor_notify()
                            #e, result = resultQueue.get(True, None)
                            try:
                                e, result = resultQueue.get(True, __fcall_timeout) # 5 seconds means pretty non-responsive.
                            except _Queue.Empty:
                                # The function call timed out. This could be a problem
                                # with the actor or it might not have been started. Check
                                # which and raise appropriately
                                if not self.is_alive():
                                    raise ActorNotStartedException
                                raise
                            if e:
                                six.reraise(*e)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION result", result)    # EXPERIMENTAL
                            return result
                        return t

                    new_dct[name] = mkcallback(fn)

                elif tag.startswith("PROCESSMETHOD"):
                    def mkcallback(func):
                        @_wraps(func)
                        def s(self, *args, **argd):
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:PROCESSMETHOD", func, args, argd) # EXPERIMENTAL
                            x = func(self)
                            if x == False:
                                return
                            self.core.append((s, self, (), {}))
                        return s

                    new_dct[name] = mkcallback(fn)

                elif tag == "LATEBIND":
                    outboxes[fn.__name__] = fn.__doc__
                    def mkcallback(func):
                        @_wraps(func)
                        def s(self, *args, **argd):
                            if strace:                                     # EXPERIMENTAL
                                Print("strace:LATEBIND", func, args, argd) # EXPERIMENTAL
                            raise UnboundActorMethod("Call to Unbound Latebind")
                        return s
                    new_dct[name] = mkcallback(fn)<commit_msg>Make calls to unbound late bound methods report which one is bust<commit_after>#!/usr/bin/python

#
# Careful with naming to deliberately allow this:
# from actor import *
#

from collections import deque as _deque
from functools import wraps as _wraps
import logging
import six
from six.moves import queue as _Queue
import sys
from threading import Thread as _Thread
import time
import sys

__all__ = ["Actor", "ActorMixin", "ActorMetaclass",
           "actor_method", "actor_function", "process_method",
           "late_bind", "UnboundActorMethod", "ActorException",
           "ActorNotStartedException",
           "late_bind_safe", "pipe", "wait_for", "stop", "pipeline",
           "wait_KeyboardInterrupt", "start"]


strace = False  #NOTE: Overview documented
trace_actor_calls = False

class UnboundActorMethod(Exception): #NOTE: Overview documented
    pass

class ActorNotStartedException(Exception): #NOTE: Overview documented
    pass


class ActorException(Exception):   #NOTE: Overview documented
    def __init__(self, *argv, **argd):
        super(ActorException, self).__init__(*argv)
        self.__dict__.update(argd)

def Print(*args):   #NOTE: Overview documented
    sys.stderr.write(" ".join([str(x) for x in args]))
    sys.stderr.write("\n")
    sys.stderr.flush()


class ActorMetaclass(type):   #NOTE: Overview documented
    def __new__(cls, clsname, bases, dct):
        new_dct = {}
        inboxes = {}
        outboxes = {}
        for name, val in dct.items():
            new_dct[name] = val
            if val.__class__ == tuple and len(val) == 3:
                tag, fn, arg = str(val[0]), val[1], val[2]
                if tag.startswith("ACTORFUNCTION"):
                    def mkcallback(func, __fcall_timeout=arg):
                        resultQueue = _Queue.Queue()
                        @_wraps(func)
                        def t(self, *args, **argd):
                            op = (func, self, args, argd)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION args", op)          # EXPERIMENTAL
                            self.F_inbound.append((op, resultQueue))
                            self._actor_notify()
                            #e, result = resultQueue.get(True, None)
                            try:
                                e, result = resultQueue.get(True, __fcall_timeout) # 5 seconds means pretty non-responsive.
                            except _Queue.Empty:
                                # The function call timed out. This could be a problem
                                # with the actor or it might not have been started. Check
                                # which and raise appropriately
                                if not self.is_alive():
                                    raise ActorNotStartedException
                                raise
                            if e:
                                six.reraise(*e)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION result", result)    # EXPERIMENTAL
                            return result
                        return t

                    new_dct[name] = mkcallback(fn,arg)

            if val.__class__ == tuple and len(val) == 2:
                tag, fn = str(val[0]), val[1]
                if tag.startswith("ACTORMETHOD"):
                    inboxes[fn.__name__] = fn.__doc__
                    def mkcallback(func):
                        @_wraps(func)
                        def t(self, *args, **argd):
                            if strace:                                            # EXPERIMENTAL
                                Print("strace:CALL ACTORMETHOD", func, args, argd)# EXPERIMENTAL
                            self.inbound.append((func, self, args, argd))
                            self._actor_notify()
                        return t
                    new_dct[name] = mkcallback(fn)

                elif tag.startswith("ACTORFUNCTION"):
                    def mkcallback(func):
                        resultQueue = _Queue.Queue()

                        @_wraps(func)
                        def t(self, __fcall_timeout=5, *args, **argd):
                            op = (func, self, args, argd)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION args", op)          # EXPERIMENTAL
                            self.F_inbound.append((op, resultQueue))
                            self._actor_notify()
                            #e, result = resultQueue.get(True, None)
                            try:
                                e, result = resultQueue.get(True, __fcall_timeout) # 5 seconds means pretty non-responsive.
                            except _Queue.Empty:
                                # The function call timed out. This could be a problem
                                # with the actor or it might not have been started. Check
                                # which and raise appropriately
                                if not self.is_alive():
                                    raise ActorNotStartedException
                                raise
                            if e:
                                six.reraise(*e)
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:ACTORFUNCTION result", result)    # EXPERIMENTAL
                            return result
                        return t

                    new_dct[name] = mkcallback(fn)

                elif tag.startswith("PROCESSMETHOD"):
                    def mkcallback(func):
                        @_wraps(func)
                        def s(self, *args, **argd):
                            if strace:                                          # EXPERIMENTAL
                                Print("strace:PROCESSMETHOD", func, args, argd) # EXPERIMENTAL
                            x = func(self)
                            if x == False:
                                return
                            self.core.append((s, self, (), {}))
                        return s

                    new_dct[name] = mkcallback(fn)

                elif tag == "LATEBIND":
                    outboxes[fn.__name__] = fn.__doc__
                    def mkcallback(func):
                        @_wraps(func)
                        def s(self, *args, **argd):
                            if strace:                                     # EXPERIMENTAL
                                Print("strace:LATEBIND", func, args, argd) # EXPERIMENTAL
                            raise UnboundActorMethod("Call to Unbound Latebind", func)
                        return s
                    new_dct[name] = mkcallback(fn)
{'fraction_non_alphanumeric': 0.0788758581235698, 'fraction_numerical': 0.0014302059496567505, 'mean_word_length': 1.062380179914467, 'pattern_counts': {'":': 2, '<': 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': 50, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '55164', 'n_tokens_mistral': 3409, 'n_tokens_neox': 3229, 'n_words': 843}