Running Flask App in Background

0
down vote
favorite
I have the following build configuration in my config.yml file for CircleCI:

  - run:
      name: Start API
      command: |
        . dq/bin/activate
        python3 api/run.py
        background: true

  - run:
      name: Run Tests
      command: |
        . dq/bin/activate
        nose2 --plugin nose2.plugins.junitxml --junit-xml -v

Basically I want to start my API with the command python3 api/run.py so that I can run my test in the following steps (tests are sending http requests to the API).

The background: true option does not seem to work as expected. The API starts but my build freezes and does not go to the following step.

Am I doing anything wrong?

Note that I have also posted the question on Stack Overflow here:
https://stackoverflow.com/questions/48763185/build-stuck-due-to-background-process-in-circleci

I’m not sure what’s happening, this issue does not seem to be due to background: true
I have removed it and now my build freezes anyway. It executes api/run.py as described below but unit tests are not being executed by nose2.

  - run:
      name: Run Tests
      command: |
        . dq/bin/activate
        python3 api/run.py
        nose2 --plugin nose2.plugins.junitxml --junit-xml -v

I don’t understand why.
Tests run fine locally.
Any help would be appreciated

Pro-tip: when cross-posting between channels, always declare your cross-posting. This will allow readers to check if you have acquired answers on your duplicates prior to making what might be a pointless effort in answering.

1 Like

I have been able to run my build successfully with the following configuration:

  - run:
      name: Run Tests
      command: |
        . dq/bin/activate
        python3 api/run.py &
        nose2 --plugin nose2.plugins.junitxml --junit-xml -v

This one worked as well and seems to be a better practice as it’s using the flag background: true. I was not indenting it properly in my previous attempt.

  - run:
      name: Start API
      command: |
        . dq/bin/activate
        python3 api/run.py
      background: true

  - run:
      name: Run Tests
      command: |
        . dq/bin/activate
        nose2 --plugin nose2.plugins.junitxml --junit-xml -v
1 Like