giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.38k forks source link

[windows] enable service start/stop commands #1721

Open dothebart opened 4 years ago

dothebart commented 4 years ago

I'd like to suggest to enable these commended out code paths: https://github.com/giampaolo/psutil/blob/master/psutil/_pswindows.py#L603

since at least on windows 10 I've seen that it at least doesn't block as rigerous as described in the comment and in https://github.com/giampaolo/psutil/issues/795 . after invoking stop() I've seen stop_pending in a loop waiting for the service to be stopped, and after start() I've seen start_pending. I've verified that using ArangoDB which takes a while to start/stop, so these states can be observed:


service = psutil.win_service_get('ArangoDB')

print(service.status())
if service.status() == 'running':
    print("arangod running - first check with arangosh: ")
    service.stop()
while service.status() != "stopped":
    print(service.status())
    time.sleep(1)
service.start()

while service.status() != "running":
    print(service.status())
    time.sleep(1)

(ps: psutils currently seem to be the only python 3 working solution to manipulate services)

arshianoor5 commented 2 years ago

I am working on a project where i need to check multiple services staus all together… I can add using list but I don’t know if it will work can anyone help me with that?

dothebart commented 2 years ago

have a look at how we monkey-patch psutil to achieve this: https://github.com/arangodb/release-test-automation/blob/main/release_tester/tools/monkeypatch_psutil.py https://github.com/arangodb/release-test-automation/blob/main/release_tester/arangodb/installers/nsis.py#L26