简体   繁体   中英

Cant trigger python 3 code with asterisk AGI even on using subprocess inside python2

I am running a python2 code which is triggered by dial plan. In order to process saved recording I need to run a python 3 script. Is there any way to do it. If I am switching the code to python3 the code is not working. This is the extension same=>n,AGI(code.py)

in code.py on giving the header #!/usr/bin/env python2

i am able to run the function

def run_cmd(cmd):
#This runs the general command 
   sys.stderr.write(cmd)
   sys.stderr.flush()
   sys.stdout.write(cmd)
   sys.stdout.flush()
   result = sys.stdin.readline().strip()
   checkresult(result)

which is able to process various agi command but on switching it to python 3 #!/usr/bin/env python3 code wont run. Now I need to use google cloud engine to process something thats written in python 3

Is there a way to make it run i have done

def run_sys_command(command):
   subprocess.call(command, shell=True)
   checkresult(result)
  
command = "sudo python3 /root/Downloads/check2.py"
run_sys_command(command)

Is there any way to run the python 3 script or any way to run python 3 script directly with agi.

I have checked permission n everything

Sure you can run threads inside AGI.

But it should be stopped before AGI script end.

The simplest way do what you want - setup some type of queue(rabbitmq/simple tasks list in mysql?) and process it outside asterisk process scope.

There is no any problem with running python3 as AGI script. I have plenty of such scripts in my projects. Just check your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM