Search code examples
pythondjangoserversubprocessport

How can I exit a subprocess that calls a django server?


I am running an otree erperiment on a django server on localhost:8000 and I want to run a subprocess that starts another django server on 8080. The browser tab will not open if in first order the subprocess is called. How can I fix this? How can I quit the new server (and the browser tab) and go back to my first one?

This is for an oTree experiment. During this experiment, I need to open another django project, specially I want to run a django-oscar shop.

class MyPage2(Page):

    def before_next_page(self):
       os.environ['DJANGO_SETTINGS_MODULE'] = 'shop.settings'
       subprocess.call(['py', 'shop2/manage.py', 'runserver', '0.0.0.0:8080'], shell=True)
       webbrowser.open('http://localhost:8080', new=2)

Solution

  • Solved this a little differently. I have waived the sub processes and have created an API with django REST framework instead. Passing parameters back and forth (and working within the same browser tab) were imho the best approach.