Taking a long time to execute a saltstack command using python

梦想与她 提交于 2019-12-25 07:39:49

问题


I was trying to execute this saltstack command cmd = "/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/" output = os.popen(cmd).readlines() using python. I have started 8 threads in parallel to run this command, but each thread costs about 5 min to finish. But I run this command in terminal or python console standalone, it just takes me about 2-3 secs to complete. First I thought it was because of readlines() consuming lots of memory, but it still costs 5 min more to finish when I removed readlines() just to run the shell command with os.popen(). I have no idea why it takes so much time to run this command, any solutions to this? Thx guys

I have found that it consumes around 5 sec to execute output = os.popen("/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/") other than output = os.popen(cmd). The variable cmd is exactly the same with "/usr/local/bin/salt -L 'target' cp.get_dir salt://allapps/V001 /u02/tomcat-8.0.24/8080/webapps/". Why there is so much difference?


回答1:


I'm not sure why that command is taking so long. Have you considered using Salt's python api? https://docs.saltstack.com/en/latest/ref/clients/index.html#python-api



来源:https://stackoverflow.com/questions/33405520/taking-a-long-time-to-execute-a-saltstack-command-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!