LINUX.ORG.RU

История изменений

Исправление Qwentor, (текущая версия) :

Файл для запуска основного через cron:

import psutil
import subprocess
import os


class cd:
	"""Context manager for changing the current working directory"""
	def __init__(self, newPath):
		self.newPath = os.path.expanduser(newPath)

	def __enter__(self):
		self.savedPath = os.getcwd()
		os.chdir(self.newPath)

	def __exit__(self, etype, value, traceback):
		os.chdir(self.savedPath)

dir_path = os.path.dirname(os.path.realpath(__file__))
flag = False
pids = psutil.pids()
for pid in pids:
	pid = psutil.Process(pid)
	if(pid.name() == 'python3'):
		if(pid.cmdline()[1] == 'vpn_v.py'):
			flag = True

if(flag):
	pass
else:
	with cd(dir_path):
		proc = subprocess.Popen(['nohup', 'python3','vpn_v.py', '&'], stderr=subprocess.PIPE)
	

Исходная версия Qwentor, :

Файл для запуска основного через cron:

import psutil
import subprocess
import os


class cd:
	"""Context manager for changing the current working directory"""
	def __init__(self, newPath):
		self.newPath = os.path.expanduser(newPath)

	def __enter__(self):
		self.savedPath = os.getcwd()
		os.chdir(self.newPath)

	def __exit__(self, etype, value, traceback):
		os.chdir(self.savedPath)

dir_path = os.path.dirname(os.path.realpath(__file__))
f = open(dir_path + '/test2', 'a')
f.write('eeee'+'\n')
f.close()

flag = False
pids = psutil.pids()
for pid in pids:
	pid = psutil.Process(pid)
	if(pid.name() == 'python3'):
		if(pid.cmdline()[1] == 'vpn_v.py'):
			flag = True

if(flag):
	pass
else:
	with cd(dir_path):
		proc = subprocess.Popen(['nohup', 'python3','vpn_v.py', '&'], stderr=subprocess.PIPE)