I assume you want something like this:
import subprocess import time class foo_class(object): def __init__(self): self.foo = None def start(self): self.stop() self.foo = subprocess.Popen(['a daemon service']) self.foo.start() def stop(self): if self.foo: self.foo.kill() self.foo.wait() self.foo = None foo = foo_class() foo.start() time.sleep(5) foo.stop()
Some things I changed:
- Import should usually be at the top of the file.
- Classes must inherit from
object . - You want to use an instance variable.
- For your class class names, it doesn't make sense to start with the class name.
- When calling its methods, you created a new instance of
foo_class . Instead, you want to create one instance and call it methods.
source share