Add _unload functionality
This commit is contained in:
parent
5eb0c9df84
commit
c3cc449fee
1 changed files with 12 additions and 0 deletions
12
main.py
12
main.py
|
@ -11,6 +11,18 @@ class Plugin:
|
||||||
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
|
||||||
async def _main(self):
|
async def _main(self):
|
||||||
# startup
|
# startup
|
||||||
|
print("PowerTools starting...")
|
||||||
self.backend_proc = subprocess.Popen([PARENT_DIR + "/bin/backend"])
|
self.backend_proc = subprocess.Popen([PARENT_DIR + "/bin/backend"])
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
async def _unload(self):
|
||||||
|
# shutdown
|
||||||
|
print("PowerTools unloading...")
|
||||||
|
if self.backend_proc is not None:
|
||||||
|
self.backend_proc.terminate()
|
||||||
|
try:
|
||||||
|
self.backend_proc.wait(timeout=5) # 5 seconds timeout
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
self.backend_proc.kill()
|
||||||
|
self.backend_proc = None
|
||||||
|
|
Loading…
Reference in a new issue