Include perfclient in pdm.cli's exports.
[pdm.git] / pdm / cli.py
index da6bcc5..65d5a89 100644 (file)
@@ -6,7 +6,7 @@ provided in the pdm.srv module.
 
 import socket, pickle, struct, select, threading
 
-__all__ = ["client", "replclient"]
+__all__ = ["client", "replclient", "perfclient"]
 
 class protoerr(Exception):
     pass
@@ -47,6 +47,9 @@ class client(object):
     def close(self):
         self.sk.close()
 
+    def fileno(self):
+        return self.sk.fileno()
+
     def readline(self):
         while True:
             p = self.buf.find("\n")
@@ -136,7 +139,7 @@ class perfproxy(object):
             self.cl.run("subs", self.id)
         self.subscribers.add(cb)
 
-    def unsubscribe(self):
+    def unsubscribe(self, cb):
         if cb not in self.subscribers:
             raise ValueError("Not subscribed")
         self.subscribers.remove(cb)
@@ -150,8 +153,13 @@ class perfproxy(object):
             except: pass
 
     def close(self):
-        self.cl.run("unbind", self.id)
-        del self.cl.proxies[self.id]
+        if self.id is not None:
+            self.cl.run("unbind", self.id)
+            del self.cl.proxies[self.id]
+            self.id = None
+
+    def __del__(self):
+        self.close()
 
     def __enter__(self):
         return self