Já na Udemy o Curso "Selenium WebDriver Superando os Problemas."
Acesse o link abaixo com desconto.
.conf
file to connect the vm.[credentials]
host = <server name in domain>
domain = <domain name>
user = <user name in server>
pass = <password>
[options]
cache_file = <name of cache file>
sync_interval = <interval in hours to make new cache file>
hypy.py --help
hypy.py --help
Usage: hypy.py [OPTIONS] COMMAND [ARGS]...
Multiplataform Hyper-V Manager using Python and FreeRDP
Options:
--help Show this message and exit.
Commands:
connect Connect to virtual machine identified by...
create Create a new snapshot with vm's current state
delete Delete a machine's snapshot by name
list List virtual machines and its indexes
pause Pause virtual machine identified by index
restore Restore virtual machine snapshot
resume Resume (paused) virtual machine identified by...
snaps List virtual machine snapshots
start Start virtual machine identified by index
stop Stop virtual machine identified by index
If you need help on any subcommand, run hypy.py COMMAND --help
Autor: Gabriel Avanzi.
https://github.com/avanzzzi/hypy
children
(recursive=False)Process
objects, preemptively checking whether PID has been reused. If recursive is True return all the parent descendants. Example assuming A == this process:A ─┐
│
├─ B (child) ─┐
│ └─ X (grandchild) ─┐
│ └─ Y (great grandchild)
├─ C (child)
└─ D (child)
>>> p.children()
B, C, D
>>> p.children(recursive=True)
B, X, Y, C, D
Note that in the example above if process X disappears process Y won’t be returned either as the reference to process A is lost.# Funcao do PsUtil pra matar os processos filhos de forma recursiva, # caso der erro ao matar o processo, no .json tem alguns selecionados. def kill_recursive(self, proc_pid, json_file): print ( "Matando o Processo de Forma Recursiva: " +str(proc_pid)) try: process = Process(proc_pid) for proc in process.children(recursive=True): proc.kill() process.kill() except NoSuchProcess: print ("o processo nao existe mais.") self.list_kill(json_file)
self.process = Popen([sys.executable, self.command], creationflags =CREATE_NEW_CONSOLE,stdin=PIPE, stdout=PIPE, stderr=PIPE, )
import subprocess
import psutil
class TaskKill:
def __init__(self):
pass
# funcao que me passa o nome do app e me retorna o pid.
def list_pid(self, app):
pid = ''
if app:
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name'])
if pinfo['name'] == app:
pid = pinfo['pid']
except psutil.NoSuchProcess:
print "o processo nao existe mais."
return pid
else:
print(pinfo)
else:
print "Voce precisa enviar o nome do processo!"
return pid
# funcao que me passa uma lista de processo por nome e me retorna uma lista de processos.
def lista_processos(self, app):
proc_kill = []
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name'])
if pinfo['name'] == app:
proc_kill.append(proc)
except psutil.NoSuchProcess:
print "O processo nao existe mais."
pass
else:
print(pinfo)
return proc_kill
# Funcao que forca matar o processo via force no console.
def kill_force(self, pid):
if pid:
p = psutil.Process(pid)
app = p.name()
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name'])
if pinfo['name'] == app:
print "notepad found!"
subprocess.check_output('taskkill /PID ' + str(pid) + ' /F', shell=True)
return True
except Exception, e:
print "Erro Desconhecido: ", e
pass
else:
print "Pid nao enviado!"
return False
def on_terminate(self, proc):
print("process {} terminated with exit code {}".format(proc, proc.returncode))
# funcao de envia uma lista de processos e mata o processo via psutil.
def psutil_kill(self, procs_kill):
status = False
procs = procs_kill # a list of Process instances
for p in procs:
try:
p.terminate()
print "Terminate processo!"
status = True
except psutil.NoSuchProcess:
print "O processo nao existe mais."
pass
gone, alive = psutil.wait_procs(procs, timeout=10, callback=on_terminate)
for p in alive:
print ("couldn't terminate process %s" % p)
try:
p.kill()
print "Kill processo!"
status = True
except psutil.NoSuchProcess:
print "O processo nao existe mais."
return status
# funcao que matar um processo de forma remota na rede, usando o pskill.
def kill_force_remote(self, computer, pid, user, password):
print "notepad found!"
try:
subprocess.check_output(
'C:\SysinternalsSuite\pskill.exe -t \\' + '\\' + str(computer) + ' -u ' + str(user) + ' -p ' + \
str(password) + ' ' + str(pid), shell=True)
return True
except Exception, e:
print "Erro generico: ", e
return False
if __name__ == '__main__':
obj = TaskKill()
pid_num = obj.list_pid('notepad++.exe')
test = obj.kill_force(pid_num)
print "Kill App: " + str(test)
C:\Python27\python.exe C:/Users/reiload/Dropbox/python_functions/kill_app.py {'pid': 0, 'name': 'System Idle Process'} {'pid': 4, 'name': 'System'} {'pid': 7120, 'name': 'chrome.exe'} {'pid': 7444, 'name': 'chrome.exe'} {'pid': 7548, 'name': 'WUDFHost.exe'} {'pid': 7964, 'name': 'zatray.exe'} {'pid': 8064, 'name': 'chrome.exe'} {'pid': 8088, 'name': 'taskhostex.exe'} {'pid': 8128, 'name': 'GWX.exe'} {'pid': 9028, 'name': 'python.exe'} {'pid': 9124, 'name': 'dasHost.exe'} {'pid': 9272, 'name': 'chrome.exe'} {'pid': 9368, 'name': 'chrome.exe'} {'pid': 9396, 'name': 'chrome.exe'} {'pid': 9556, 'name': 'cmd.exe'} {'pid': 9820, 'name': 'chrome.exe'} {'pid': 10084, 'name': 'jucheck.exe'} {'pid': 10164, 'name': 'cmd.exe'} {'pid': 10324, 'name': 'audiodg.exe'} {'pid': 10836, 'name': 'chrome.exe'} {'pid': 10848, 'name': 'conhost.exe'} {'pid': 11832, 'name': 'python.exe'} {'pid': 12316, 'name': 'fsnotifier.exe'} {'pid': 12320, 'name': 'pycharm.exe'} {'pid': 12620, 'name': 'conhost.exe'} {'pid': 12812, 'name': 'python.exe'} {'pid': 12864, 'name': 'taskeng.exe'} {'pid': 12932, 'name': 'chrome.exe'} {'pid': 13080, 'name': 'chrome.exe'} {'pid': 13188, 'name': 'conhost.exe'} {'pid': 13544, 'name': 'conhost.exe'} {'pid': 14564, 'name': 'chrome.exe'} {'pid': 15032, 'name': 'notepad++.exe'} notepad found! Kill App: True Process finished with exit code 0