X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=pdm%2Fperf.py;h=7d8b48b114e754bcd28059a66c2f5825a4a2e652;hb=864a9d46e7cc4a67bd244947b933baabc69c902f;hp=de2dba5450a3d7f25c2e1fe9cafea43cfbe7410e;hpb=87b07b36f1db22383d75ad59f6bf8e48bf03f54f;p=pdm.git diff --git a/pdm/perf.py b/pdm/perf.py index de2dba5..7d8b48b 100644 --- a/pdm/perf.py +++ b/pdm/perf.py @@ -6,14 +6,14 @@ class attrinfo(object): class perfobj(object): def __init__(self, *args, **kwargs): - super(perfobj, self).__init__() + super().__init__() def pdm_protocols(self): return [] class simpleattr(perfobj): def __init__(self, func, info = None, *args, **kwargs): - super(simpleattr, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.func = func if info is None: info = attrinfo() @@ -26,11 +26,11 @@ class simpleattr(perfobj): return self.info def pdm_protocols(self): - return super(simpleattr, self).pdm_protocols() + ["attr"] + return super().pdm_protocols() + ["attr"] class valueattr(perfobj): def __init__(self, init, info = None, *args, **kwargs): - super(valueattr, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.value = init if info is None: info = attrinfo() @@ -43,12 +43,12 @@ class valueattr(perfobj): return self.info def pdm_protocols(self): - return super(valueattr, self).pdm_protocols() + ["attr"] + return super().pdm_protocols() + ["attr"] class eventobj(perfobj): def __init__(self, *args, **kwargs): - super(eventobj, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.subscribers = set() def subscribe(self, cb): @@ -66,11 +66,11 @@ class eventobj(perfobj): except: pass def pdm_protocols(self): - return super(eventobj, self).pdm_protocols() + ["event"] + return super().pdm_protocols() + ["event"] class staticdir(perfobj): def __init__(self, *args, **kwargs): - super(staticdir, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.map = {} def __setitem__(self, name, ob): @@ -86,13 +86,13 @@ class staticdir(perfobj): return self.map.get(name, default) def listdir(self): - return self.map.keys() + return list(self.map.keys()) def lookup(self, name): return self.map[name] def pdm_protocols(self): - return super(staticdir, self).pdm_protocols() + ["dir"] + return super().pdm_protocols() + ["dir"] class event(object): def __init__(self): @@ -100,21 +100,32 @@ class event(object): idlock = threading.Lock() procevid = 0 -class startevent(event): + +def getprocid(): + global procevid + idlock.acquire() + try: + ret = procevid + procevid += 1 + return ret + finally: + idlock.release() + +class procevent(event): + def __init__(self, id): + super().__init__() + if isinstance(id, procevent): + self.id = id.id + else: + self.id = id + +class startevent(procevent): def __init__(self): - super(startevent, self).__init__() - global procevid - idlock.acquire() - try: - self.id = procevid - procevid += 1 - finally: - idlock.release() - -class finishevent(event): + super().__init__(getprocid()) + +class finishevent(procevent): def __init__(self, start, aborted): - super(finishevent, self).__init__() - self.id = start.id + super().__init__(start) self.aborted = aborted sysres = staticdir()