add 'kill' method
This commit is contained in:
parent
9ead239c9f
commit
7a136f236f
|
@ -6,7 +6,7 @@
|
||||||
____
|
____
|
||||||
## ffmpeger.py
|
## ffmpeger.py
|
||||||
**Description:** FFmpeg management from Python
|
**Description:** FFmpeg management from Python
|
||||||
**Dependencies:** Python 3 (tested version 3.9.5), installed or downloaded ffmpeg, srchproc.py in the same directory
|
**Dependencies:** Python 3 (tested version 3.9.5), installed or downloaded ffmpeg, [srchproc.py](https://git.hmp.today/pavel.muhortov/utils#srchproc-py) in the same directory
|
||||||
|
|
||||||
| PARAMETERS | DESCRIPTION | DEFAULT|
|
| PARAMETERS | DESCRIPTION | DEFAULT|
|
||||||
|-------------|-------------|--------|
|
|-------------|-------------|--------|
|
||||||
|
@ -35,6 +35,7 @@ from ffmpeger import FFmpeg
|
||||||
|
|
||||||
FFmpeg.run(src='null, anull', preset='240p', fps=10)
|
FFmpeg.run(src='null, anull', preset='240p', fps=10)
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
## sendmail.py
|
## sendmail.py
|
||||||
**Description:** Sending email from Python
|
**Description:** Sending email from Python
|
||||||
|
@ -72,6 +73,7 @@ msg = Mail(smtp_user='user@gmail.com', smtp_pass='pass', mail_dest='addr1@gmail.
|
||||||
log = msg.send()
|
log = msg.send()
|
||||||
print(log)
|
print(log)
|
||||||
```
|
```
|
||||||
|
|
||||||
____
|
____
|
||||||
## srchproc.py
|
## srchproc.py
|
||||||
**Description:** Find a running process from Python
|
**Description:** Find a running process from Python
|
||||||
|
@ -83,6 +85,7 @@ ____
|
||||||
|**[--find]**|find process pid, name or arguments||
|
|**[--find]**|find process pid, name or arguments||
|
||||||
|**[--exclude]**|exclude process pid, name or arguments|`None`|
|
|**[--exclude]**|exclude process pid, name or arguments|`None`|
|
||||||
|**[--self]**|find a clones of self|`True`|
|
|**[--self]**|find a clones of self|`True`|
|
||||||
|
|**[--kill]**|kill the process with pid||
|
||||||
|
|
||||||
Example usage in terminal with Python for find all running processes:
|
Example usage in terminal with Python for find all running processes:
|
||||||
```shell
|
```shell
|
||||||
|
@ -104,4 +107,3 @@ if processes:
|
||||||
for process in processes:
|
for process in processes:
|
||||||
print(process)
|
print(process)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
23
srchproc.py
23
srchproc.py
|
@ -58,12 +58,10 @@ class Proc:
|
||||||
Find all running process
|
Find all running process
|
||||||
:return: list of dictionaries with descriptions of found processes
|
:return: list of dictionaries with descriptions of found processes
|
||||||
"""
|
"""
|
||||||
if platform.startswith('linux'):
|
if platform.startswith('linux') or platform.startswith('darwin'):
|
||||||
return cls._list_linux()
|
return cls._list_linux()
|
||||||
elif platform.startswith('win32'):
|
elif platform.startswith('win32'):
|
||||||
return cls._list_windows()
|
return cls._list_windows()
|
||||||
elif platform.startswith('darwin'):
|
|
||||||
return cls._list_linux()
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -92,6 +90,18 @@ class Proc:
|
||||||
else:
|
else:
|
||||||
return proc_found
|
return proc_found
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def kill(cls, pid: int):
|
||||||
|
"""
|
||||||
|
Kill the process by means of the OS
|
||||||
|
:param pid: process ID
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
if platform.startswith('linux') or platform.startswith('darwin'):
|
||||||
|
Popen(['kill', '-s', 'SIGKILL', str(pid)])
|
||||||
|
elif platform.startswith('win32'):
|
||||||
|
Popen(['taskkill', '/PID', str(pid), '/F'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
@ -107,8 +117,13 @@ if __name__ == "__main__":
|
||||||
help='exclude process pid, name or arguments')
|
help='exclude process pid, name or arguments')
|
||||||
args.add_argument('--self', action='store_true', required=False,
|
args.add_argument('--self', action='store_true', required=False,
|
||||||
help='find a clones of self')
|
help='find a clones of self')
|
||||||
|
args.add_argument('--kill', type=int, required=False,
|
||||||
|
help='kill the process with pid')
|
||||||
args = vars(args.parse_args())
|
args = vars(args.parse_args())
|
||||||
if args['find']:
|
processes = None
|
||||||
|
if args['kill']:
|
||||||
|
Proc.kill(args['kill'])
|
||||||
|
elif args['find']:
|
||||||
processes = Proc.search(args['find'], args['exclude'])
|
processes = Proc.search(args['find'], args['exclude'])
|
||||||
elif args['self']:
|
elif args['self']:
|
||||||
processes = Proc.search(' '.join(argv), str(getpid()))
|
processes = Proc.search(' '.join(argv), str(getpid()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user