<commit_before>from events import *
import thread

class EventManager:
	def __init__(self):
		from weakref import WeakKeyDictionary
		self.listeners = WeakKeyDictionary()
		self.eventQueue = []
		self.nextQueue = []
		self.listenersToAdd = []
		self.listenersToRemove = []
		self.postLock = thread.allocate_lock()
	
	def register_listener(self, listener):
		self.listenersToAdd.append(listener)
	
	def update_listeners(self):
		for listener in self.listenersToAdd:
			self.listeners[listener] = 1
		for listener in self.listenersToRemove:
			if listener in self.listeners:
				del self.listeners[listener]
	
	def unregister_listener(self, listener):
		self.listenersToRemove.append(listener)
	
	def post(self, event):
		self.eventQueue.append(event)
		if isinstance(event, TickEvent):
			self.update_listeners()
			self.consume_event_queue()
		else:
			if not event.silent:
				print(event.name)
				
	def post_next(self, event):
		self.nextQueue.append(event)
		if not event.silent:
				print("Next", event.name)
	
	def consume_event_queue(self):
		i = 0
		while i < len(self.eventQueue):
			event = self.eventQueue[i]
			for listener in self.listeners.keys():
				listener.notify(event)
			i += 1
			if self.listenersToAdd or self.listenersToRemove:
				self.update_listeners()
		self.eventQueue = self.nextQueue
		self.nextQueue = []<commit_msg>Notify now runs in multiple threads.<commit_after>from events import *
import thread

class EventManager:
	def __init__(self):
		from weakref import WeakKeyDictionary
		self.listeners = WeakKeyDictionary()
		self.eventQueue = []
		self.nextQueue = []
		self.listenersToAdd = []
		self.listenersToRemove = []
		self.postLock = thread.allocate_lock()
	
	def register_listener(self, listener):
		self.listenersToAdd.append(listener)
	
	def update_listeners(self):
		for listener in self.listenersToAdd:
			self.listeners[listener] = 1
		for listener in self.listenersToRemove:
			if listener in self.listeners:
				del self.listeners[listener]
	
	def unregister_listener(self, listener):
		self.listenersToRemove.append(listener)
	
	def post(self, event):
		self.eventQueue.append(event)
		if isinstance(event, TickEvent):
			self.update_listeners()
			self.consume_event_queue()
		else:
			if not event.silent:
				print(event.name)
				
	def post_next(self, event):
		self.nextQueue.append(event)
		if not event.silent:
				print("Next", event.name)
	
	def consume_event_queue(self):
		i = 0
		while i < len(self.eventQueue):
			event = self.eventQueue[i]
			for listener in self.listeners.keys():
				thread.start_new_thread(listener.notify, (event, ))
			i += 1
			if self.listenersToAdd or self.listenersToRemove:
				self.update_listeners()
		self.eventQueue = self.nextQueue
		self.nextQueue = []
{'fraction_non_alphanumeric': 0.10480349344978165, 'fraction_numerical': 0.002183406113537118, 'mean_word_length': 4.206439393939394, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3264983', 'n_tokens_mistral': 1032, 'n_tokens_neox': 885, 'n_words': 194}