Don't call stop uselessly at shutdown
authorEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 15:26:44 +0000 (23:26 +0800)
committerEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 15:26:44 +0000 (23:26 +0800)
zavai/gps.py
zavai/registry.py

index e861e1cc6d9339e6d7d81a141d99071c0faa5a4a..8be490ab45abc86a360c70cad6a8f013816fd54f 100755 (executable)
@@ -208,7 +208,6 @@ class GPX(zavai.Service):
         conf = registry.resource("conf")
         self.trackdir = conf.homedir
         self.activity_monitors = set()
-        self.started = False
 
     def add_activity_monitor(self, cb):
         self.activity_monitors.add(cb)
@@ -223,17 +222,14 @@ class GPX(zavai.Service):
 
     def start(self):
         zavai.info("Starting GPX trace subsystem")
-        self.started = True
         gps = self.registry.resource("gps")
         gps.position.connect("position", self.on_position_changed)
 
     def stop(self):
-        if not self.started: return
         zavai.info("Stopping GPX trace subsystem")
         gps = self.registry.resource("gps")
         gps.position.disconnect("position", self.on_position_changed)
         self.stop_track()
-        self.started = False
 
     def on_position_changed(self, fields, tstamp, lat, lon, alt):
         self.last_pos = (fields, tstamp, lat, lon, alt)
index 67f4c78f6aa737971898455de44d75c07b481584..4fc210143ecb8568f3ad692328dbea2665db80d1 100644 (file)
@@ -169,9 +169,11 @@ class Service(Resource):
         self.callbacks = dict()
         for t in types:
             self.callbacks[t] = set()
+        self.started = False
 
     def shutdown(self):
-        self.stop()
+        if self.started:
+            self.stop()
 
     def start(self):
         "Activate the service"
@@ -197,6 +199,7 @@ class Service(Resource):
         self.callbacks[type].add(callback)
         if do_start:
             self.start()
+            self.started = True
 
     def disconnect(self, type, callback):
         "Disconnect a callback to this resource, activating it if needed"
@@ -204,3 +207,4 @@ class Service(Resource):
         self.callbacks[type].discard(callback)
         if not self.has_callbacks():
             self.stop()
+            self.started = False