Forums

subprocess.Popen not running on pythonanywhere but on works on local machine - any idea why or how to catch error ?

.

from flask import Flask, render_template, request 
from flask_mysqldb import MySQL
import yaml
from subprocess import Popen, PIPE
from threading import Thread
import time 
import subprocess


app = Flask(__name__)
db = yaml.full_load(open('db.yaml')) 
app.config['MYSQL_HOST'] = 'xxx'
app.config["MYSQL_USER"] = "xxx"
app.config["MYSQL_PASSWORD"] = "xxx"
app.config["MYSQL_DB"] = "xxx"
mysql = MySQL(app)


@app.route("/", methods=["GET", "POST"])
def index():
    if request.method =="POST":
        #fetch form data 
        userDetails=request.form
        title=userDetails["title"]
        location=userDetails["location"]
        radius=userDetails["radius"]
        email=userDetails["email"]
        cur = mysql.connection.cursor()
        cur.execute("INSERT INTO requests(title, location, radius, email) VALUES(%s, %s, %s, %s)", (title, location, radius, email))
        mysql.connection.commit()
        cur.close()
        subprocess.Popen(['python', 'crawler.py'])
        return render_template('donenew.html')
    return render_template("indexnew.html")


if __name__ == "__main__":
    app.run(debug=True)

Did you check your web app's error log? I suppose the error would be related to the paths -- you could try using an absolute paths for the python command and crawler.py. But, I'm not sure if that's the best way to launch your crawler, if I can suggest anything. Maybe have a look at this help page.

hi yes checked the error logs but nothing is shown. not sure why there are no error logs for the subprocess which obviously does not execute. any idea how to catch errors for the subprocess ? used the absolute path, same outcome.

How do you know it does not execute? Do you expect any side effects? Is donenew.html template rendering?