<commit_before>
import time

class EventLoop(object):

	def __init__(self):
		self.__once_callbacks = []
		self.__repeat_callbacks = []

	def fini(self):
		del self.__once_callbacks[:]
		del self.__repeat_callbacks[:]

	def execute(self):
		self.__exit_called = False
		while not self.__exit_called:
			for callback in list(self.__once_callbacks):
				if callback.should_call():
					self.__once_callbacks.remove(callback)
					callback.call()
			for callback in list(self.__repeat_callbacks):
				if callback.should_call():
					callback.call()
					callback.reset()
			time.sleep(0.001)

	def exit(self):
		self.__exit_called = True

	def call(self, callback, repeat=False, timeout=0):
		if repeat:
			self.__repeat_callbacks.append(Callback(callback, timeout))
		else:
			self.__once_callbacks.append(Callback(callback, timeout))

	def cancel_call(self, callback):
		found = False
		for callback_obj in self.__once_callbacks:
			if callback_obj.callback == callback:
				self.__once_callbacks.remove(callback_obj)
				found = True
				break
		if not found:
			for callback_obj in self.__repeat_callbacks:
				if callback_obj.callback == callback:
					self.__repeat_callbacks.remove(callback_obj)
					found = True
					break
		assert found, "No such callback: %s" % callback

class Callback(object):

	def __init__(self, callback, timeout):
		self.callback = callback
		self.timeout = timeout
		self.reset()

	def reset(self):
		self.time_end = time.time() + self.timeout

	def should_call(self):
		return time.time() >= self.time_end

	def call(self):
		self.callback()<commit_msg>Issue #31: Replaced EventLoop's internals with asyncio<commit_after>import asyncio

loop = asyncio.get_event_loop()

class EventLoop(object):

	def __init__(self):
		self.__handles = {}

	def fini(self):
		for handle in self.__handles.values():
			handle.cancel()
		self.__handles.clear()

	def execute(self):
		loop.run_forever()

	def exit(self):
		loop.stop()

	def call(self, callback, repeat=False, timeout=0):
		if repeat:
			handle = loop.create_task(repeat_call(timeout, callback))
		else:
			handle = loop.call_later(timeout, callback)
		self.__handles[callback] = handle

	def cancel_call(self, callback):
		self.__handles[callback].cancel()
		del self.__handles[callback]

async def repeat_call(timeout, callback):
	while True:
		await asyncio.sleep(timeout)
		callback()
{'fraction_non_alphanumeric': 0.11275337837837837, 'fraction_numerical': 0.0033783783783783786, 'mean_word_length': 4.35972850678733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5883607', 'n_tokens_mistral': 875, 'n_tokens_neox': 755, 'n_words': 175}