<commit_before>import guv

guv.monkey_patch()

from guv import gyield, sleep
import threading
import greenlet

greenlet_ids = {}


def debug(i):
    print('{} greenlet_ids: {}'.format(i, greenlet_ids))


def f():
    greenlet_ids[1] = greenlet.getcurrent()
    debug(2)

    print('t: 1')
    gyield()
    print('t: 2')
    gyield()
    print('t: 3')


def main():
    greenlet_ids[0] = greenlet.getcurrent()
    debug(1)

    t = threading.Thread(target=f)
    t.start()
    debug(3)

    print('m: 1')
    gyield()
    print('m: 2')
    gyield()
    print('m: 3')


if __name__ == '__main__':
    main()<commit_msg>Add check to ensure that we're in the same OS thread<commit_after>import guv

guv.monkey_patch()

from guv import gyield, patcher
import threading
import greenlet

threading_orig = patcher.original('threading')

greenlet_ids = {}


def check_thread():
    current = threading_orig.current_thread()
    assert type(current) is threading_orig._MainThread


def debug(i):
    print('{} greenlet_ids: {}'.format(i, greenlet_ids))


def f():
    check_thread()
    greenlet_ids[1] = greenlet.getcurrent()
    debug(2)

    print('t: 1')
    gyield()
    print('t: 2')
    gyield()
    print('t: 3')


def main():
    check_thread()
    greenlet_ids[0] = greenlet.getcurrent()
    debug(1)

    t = threading.Thread(target=f)
    t.start()
    debug(3)

    print('m: 1')
    gyield()
    print('m: 2')
    gyield()
    print('m: 3')


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.15296495956873316, 'fraction_numerical': 0.014824797843665768, 'mean_word_length': 3.183098591549296, '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': '4850138', 'n_tokens_mistral': 579, 'n_tokens_neox': 550, 'n_words': 127}