Forums

subprocess.call() not working

I am trying to deploy my Django app that have the following view

class TransitionCreate(UpdateView):
    model = Automata
    fields = []

    # some more code

    def form_valid(self, form):
        context = self.get_context_data()
        transitions = context['transitions']
        with transaction.atomic():
        self.object = form.save()

        if transitions.is_valid():
            transitions.instance = self.object
            transitions.save()

        command = "python make_graph.py"
        subprocess.call(command, shell=True)

        return super(TransitionCreate, self).form_valid(form)

For some reason the make_graph script doesn't run when I call the view, however when I run it straight from the bash it works just fine

Perhaps the working directory isn't what you think it is? If you look on the "Web" tab, there's a working directory field. If that directory is not the one that contains the make_graph.py script, you can either change it so that it is the right one, or you can specify a full path (eg. /home/nidalmer/something/make_graph.py in your command.

@giles I have tried that already and nothing seems to change

Can I take a look at your files? We can see them from our admin interface, but we always ask for permission first.

@giles yes sure go right ahead

Thanks! I see you've changed the view to use the full path, and that all looks fine. Perhaps you could call subprocess.check_call instead of subprocess.call? That would print out some more debugging information.

Ah, hang on! I think I know what the problem is. Your web app is for Python 3.5, so I assume you've installed everything for Python 3.5. But your code is calling the python interpreter, which is 2.7.

Change the code to use python3.5 instead, and it may start working.

@giles I already tried both suggestions qnd they don't seem to help

Your code still says subprocess.call instead of subprocess.check_call -- did you change it back?

I am stuck with this problem as well

Hi there, can you be more specific about what your problem is?