def service_status(service_name):
if service_name == "kubernetes":
status = 0
services = ['etcd', 'kube-apiserver', 'kube-controller-manager',
'kube-scheduler', 'kube-proxy', 'kubelet']
for service in services:
while system("systemctl is-active %s" % service)[0].strip() == 'activating':
pass
status = status or system("systemctl is-active %s" % service)[2]
if status:
service_stop(service_name)
break
return status
else:
while system("systemctl is-active %s" % service_name)[0].strip() == 'activating':
pass
return system("systemctl is-active %s" % service_name)[2]
Using pass results in to a very CPU intensive operation. it is null operation, so it will continuously run systemctl is-active %s" % service) till it comes out of the loop. If you do
while True:
pass
It takes 100% CPU. time.sleep(1) is a better option and less CPU intensive.
Using
pass
results in to a very CPU intensive operation. it is null operation, so it will continuously runsystemctl is-active %s" % service)
till it comes out of the loop. If you doIt takes 100% CPU. time.sleep(1) is a better option and less CPU intensive.
[1] https://github.com/projectatomic/adb-utils/blob/master/utils/sccli.py#L117-L133