<commit_before>from subscription.signals import Signal
from subscription.signals.accumulators import SumAccumulator

def handler1(param):
    print('Handler1:', param)
    return 1

def handler2(param):
    print('Handler2:', param)
    return 2

mysignal = Signal()
mysignal.connect(handler1)

print('Emit')
val = mysignal.emit(1)
print('Return value:', val) # Must be 'None'

print('Emit')
mysignal.connect(handler2)
mysignal.emit(2)

print('Emit')
mysignal.disconnect(handler1)
mysignal.emit(3)

print('Emit')
mysignal.connect(handler1)
mysignal.connect(handler1)
mysignal.disconnect(handler2)
mysignal.connect(handler2)
mysignal.emit(4)

print('Emit')
mysignal.clear()
mysignal.emit(5)


print('Sum accumulator')
mysignal = Signal(accumulator=SumAccumulator())
mysignal.connect(handler1)
mysignal.connect(handler2)
val = mysignal.emit('sum')
print('Return value:', val) # Must be sum of all handlers<commit_msg>Basic example of signals<commit_after>from subscription.signals import Signal


total_tentacles = 0


def inform_of_frobnicator(frobnicator_type, num_tentacles):
    print ("A frobnicator of type '%s' with %d tentacles has arrived"
           % (frobnicator_type, num_tentacles))


def count_tentacles(frobnicator_type, num_tentacles):
    global total_tentacles
    total_tentacles += num_tentacles
    print ('Total tentacles so far: %s' % total_tentacles)


def run_if_scary(frobnicator_type, num_tentacles):
    if frobnicator_type == 'Slimy':
        print('I panic')
        import sys
        sys.exit ()


new_frobnicator = Signal()
new_frobnicator.connect(inform_of_frobnicator)
new_frobnicator.connect(count_tentacles)
new_frobnicator.connect(run_if_scary)

new_frobnicator('Friendly', 8)
new_frobnicator('Sleepy', 4)
new_frobnicator('Slimy', 12)
new_frobnicator('Hungry', 6)
{'fraction_non_alphanumeric': 0.115, 'fraction_numerical': 0.014444444444444444, 'mean_word_length': 6.0627450980392155, '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': '5416646', 'n_tokens_mistral': 673, 'n_tokens_neox': 651, 'n_words': 126}