<commit_before><commit_msg>added greentest/with_timeout.py: script to run a test with specific hub set up<commit_after>#!/usr/bin/python
"""Execute python script with hub installed.

Usage: %prog [--hub HUB] [--reactor REACTOR] program.py
"""
import sys
import optparse

def import_green(modulename):
    m = __import__('eventlet.green.' + modulename)
    m = m.green.getattr(modulename)
    return m

def import_reactor(reactor):
    m = __import__('twisted.internet.' + reactor)
    return getattr(m.internet, reactor)

def setup_hub(hub, reactor):
    if reactor is not None:
        import_reactor(reactor).install()
    if hub is not None:
        from eventlet.api import use_hub
        use_hub(hub)

def parse_args():
    hub = None
    reactor = None
    del sys.argv[0] # kill with_eventlet.py
    if sys.argv[0]=='--hub':
        del sys.argv[0]
        hub = sys.argv[0]
        del sys.argv[0]
    if sys.argv[0]=='--reactor':
        del sys.argv[0]
        reactor = sys.argv[0]
        del sys.argv[0]
    return hub, reactor

if __name__=='__main__':
    hub, reactor = parse_args()
    setup_hub(hub, reactor)
    from eventlet.api import get_hub
    hub = get_hub() # set up the hub now
    print '===HUB=%r' % hub
    if 'twisted.internet.reactor' in sys.modules:
        print '===REACTOR=%r' % sys.modules['twisted.internet.reactor']
    sys.stdout.flush()
    execfile(sys.argv[0])

{'fraction_non_alphanumeric': 0.1302491103202847, 'fraction_numerical': 0.0071174377224199285, 'mean_word_length': 2.96056338028169, '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': '2069979', 'n_tokens_mistral': 499, 'n_tokens_neox': 485, 'n_words': 124}