Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python stop running instances

# Windows

keys = ["chrome.exe", "start_hotfolder.exe", "python.exe"] # programms you want to stop
processes = [p.pid for p in psutil.process_iter() if p.name() in keys]

# exclude the own process id
pid = os.getpid()
if pid in processes:
	processes.remove(pid)

  	for pid in processes:
    	psutil.Process(pid).terminate()
    
    
# Linux
pid = os.getpid()
process_name = "my_process"
pids = list(map(int, subprocess.check_output(["pidof", process_name]).split()))
if pid in pids:
	pids.remove(pid)

for p in pids:
   	psutil.Process(p).terminate()
   	logging.info(f"Stopped process {p}")
Comment

PREVIOUS NEXT
Code Example
Python :: Distribute Candy Algorithm Python 
Python :: convert to string except missing 
Python :: python subclass with extra arguments 
Python :: place parameters tkinter 
Python :: Django is MVT Not MVC 
Python :: How to Empty a Set in Python Using the clear() Method 
Python :: threading pass keyword args example 
Python :: normalize a distribution plot 
Python :: import starting with number 
Python :: Python Tkinter Label Widget Syntax 
Python :: numerical columns 
Python :: how to check if a function is callable in puyjom 
Python :: How to sort a list by even or odd numbers using a filter? 
Python :: python if modulo 
Python :: Mirror Inverse Program in python 
Python :: from django.urls import reverse 
Python :: python zeep- SOAP protocol -WSDL/XSD?XML 
Python :: Uploading small amounts of data into memory 
Python :: rename all files in a folder and subfolder 
Python :: django muti user for 3 users 
Python :: how to detect if a key was press down 
Python :: python using boolean len 
Python :: remove from list python by index 
Python :: webhook logger python 
Python :: how to save all countries from a list in a database python 
Python :: sort files in windows order python 
Python :: how to find left top width and height on an image using python 
Python :: dataframeclient influxdb example 
Python :: add 10 min to current time django 
Python :: getting month number in python 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =