from threading import Lock, Event


class TransferEventManager(object):

    def __init__(self):
        self.events = dict()
        self.events_lock = Lock()

    def acquire_event(self, path, force_clear=False):
        with self.events_lock:
            if path in self.events:
                event_holder = self.events[path]
            else:
                event_holder = EventHolder(Event(), path, self)
                self.events[path] = event_holder
        if force_clear:
            event_holder.event.clear()
        return event_holder

    def free_event(self, path):
        with self.events_lock:
            del self.events[path]


class EventHolder(object):

    def __init__(self, event, path, condition_manager):
        self.event = event
        self.path = path
        self.condition_manager = condition_manager

    def release(self):
        self.event.set()

    def __del__(self):
        self.condition_manager.free_event(self.path)

@@ -27,16 +27,56 @@
 , Event%0A
+from weakref import WeakValueDictionary%0A
 %0A%0Aclass 
@@ -156,14 +156,35 @@
 s = 
+WeakValueDictionary(
 dict()
+)
 %0A   
@@ -612,106 +612,8 @@
 er%0A%0A
-    def free_event(self, path):%0A        with self.events_lock:%0A            del self.events%5Bpath%5D%0A%0A
 %0Acla
@@ -812,32 +812,32 @@
  release(self):%0A
+
         self.eve
@@ -849,81 +849,4 @@
 t()%0A
-%0A    def __del__(self):%0A        self.condition_manager.free_event(self.path)%0A

Fix logic related to GC of Event references using weakref.WeakValueDictionary.