python 使用自定义环境值启动TouchDesigner

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用自定义环境值启动TouchDesigner相关的知识,希望对你有一定的参考价值。

import os

def Paths(current_dir, toe_file):
	start_file = os.path.join(current_dir, toe_file)
	return start_file

def Launch(**kwargs):
	envVar = kwargs.get('envVar')
	envVal = kwargs.get('envVal')
	start_file = kwargs.get('start_file')

	os.environ[envVar] = envVal
	os.startfile(start_file)

	msg = '''
	STARTING -------------------
	File 			| {file}
	Env Variable	| {var}
	Env Value		| {val}
	'''.format(file = start_file, var = envVar, val = envVal)

	return msg

def Start_up(**kwargs):
	current_dir =	kwargs.get('current_dir')
	toe_file = kwargs.get('toe_file')
	launch_args = kwargs.get('launch_args')

	start_file = Paths(current_dir, toe_file)

	for each_set in launch_args:
		envVar = each_set.get('envVar')
		envVal = each_set.get('envVal')
		
		launch_event = Launch(envVar=envVar, envVal=envVal, start_file=start_file)
		print(launch_event)
import Launcher
import os

current_dir = os.path.dirname(os.path.abspath(__file__))
toe_file = 'startup.toe'

launch_args =[
	{
		"envVar" : 'STARTUP',
		"envVal" : 'controller_1'
	},
	{
		"envVar" : 'STARTUP',
		"envVal" : 'node_1'
	}
]

Launcher.Start_up(current_dir=current_dir, toe_file=toe_file, launch_args=launch_args)
'''
Kill process in case
'''

import psutil

#for proc in psutil.process_iter():
#    if(proc.name() == 'TouchDesigner099.exe'):
#        proc.kill()
#    print(proc.name())
    
def killList(kill_list):
    '''Process kill function'''    
    for proc in psutil.process_iter():
        # check whether the process name matches
        # print(proc.name())
        if any(procstr in proc.name() for procstr in kill_list):
            print('Killing {}'.format(proc.name()))
            proc.kill()
            
def kill_by_process_name(name):
    for proc in psutil.process_iter():
        if proc.name() == name:
            print("Killing process: " + name)
            if(check_process_exist_by_name(name)):
                print("Killing process: " + name + " sucess")
            else:
                print("Killing process: " + name + " failed")
            return
 
    print("Not found process: " + name)
 
def check_process_exist_by_name(name):
    for proc in psutil.process_iter():
        if proc.name() == name:
            return True
    return False
            
killList(['TouchDesigner099.exe', 'Photoshop.exe'])

以上是关于python 使用自定义环境值启动TouchDesigner的主要内容,如果未能解决你的问题,请参考以下文章

GCP Dataproc 自定义图像 Python 环境

SpringBoot2.0 基础案例(17):自定义启动页,项目打包和指定运行环境

在 azure ml 部署环境中导入自定义 python 模块

springboot自定义配置文件数量是变化的,属性相同,只是值不一样,怎样绑定到实体类?

Azure ML Studio 环境中的 Python 自定义模型错误 0085,在本地环境中运行良好

PySC2 环境的基本使用