0

I'm having some difficulties to develop performance of my system.

I use curl and os.popen to make my server command to some network devices.

but it doesn't seem to start simultaneously but sequentially.

is there any solution to make os.popen processes start simultaneously?

Thanks in advance.


searchStr = request.POST.get('searchInput')


search_dev_dmz = str("curl --user id:pw -k -A ASDM https://someIP/admin/exec/show+access-list+'|'+inc+"+searchStr)
search_ccs1 = str("curl --user id:pw -k -A ASDM https://someIP/admin/exec/show+access-st+'|'+inc+"+searchStr)
search_ccs2 = str("curl --user id:pw -k -A ASDM https://someIP/admin/exec/show+access-list+'|'+inc+"+searchStr)

dev_dmz = str(os.popen(search_dev_dmz).read())
ccs1 = str(os.popen(search_ccs1).read())
ccs2 = str(os.popen(search_ccs2).read())

I expected that those three popen process will start at the same time , but they seems to start sequentially.

I want to make them start simultaneously so that I can enhance ther performance of my system.

  • 1
    Possible duplicate of [How can I run an external command asynchronously from Python?](https://stackoverflow.com/questions/636561/how-can-i-run-an-external-command-asynchronously-from-python) – Olvin Roght Aug 21 '19 at 11:34

1 Answers1

0

You need multiprocess. I will give an example that uses the command "ping" but it should be easy to adapt to your code.

from multiprocessing import Pool
import os


def f(x):
    return(str(os.popen(x).read()))

if __name__ == '__main__':


  alist= ["ping -c 10 google.com", "ping -c 10 microsoft.com", "ping -c 10 stackoverflow.com"]

  p = Pool(3)
  print(p.map(f, alist))
Fabrizio
  • 772
  • 6
  • 14