Aport action is checking before launch if already aport is running

This commit is contained in:
Jakub Trllo 2019-02-19 09:49:43 +01:00
parent 7bd1f6df6a
commit c8c336bdd3

View file

@ -1,7 +1,5 @@
import os
import sys
from avalon import io
from pprint import pprint
import psutil
import acre
from avalon import api, lib
@ -25,6 +23,16 @@ class Aport(api.Action):
return True
return False
def is_running(self, filename):
procs = [p for p in psutil.process_iter() if (
'python.exe' in p.name() and
filename in p.cmdline()
)]
if len(procs) > 0:
return True
return False
def process(self, session, **kwargs):
"""Implement the behavior for when the action is triggered
@ -35,10 +43,17 @@ class Aport(api.Action):
Popen instance of newly spawned process
"""
av_core_path = os.environ.get('AVALON_CORE', None)
path_items = [
av_core_path, 'setup', 'aport', 'pythonpath', 'init.py'
]
aport_path = os.path.sep.join(path_items)
if self.is_running(aport_path):
log.info("Aport server is already running")
return
with pype.modified_environ(**session):
# Get executable by name
print(self.name)
app = lib.get_application(self.name)
executable = lib.which(app["executable"])