I have transferred forecasts.py
file from GitHub to my virtual machine via Azure Pipelines. If I start the script from the virtual machine terminal with python3 forecasts.py &
, everything goes smoothly and the script remains running in the background. For some reason, I get the following message from the Azure Pipelines, if I try to start that script similarly:
The STDIO streams did not close within 10 seconds of the exit event from process '/bin/bash'. This may indicate a child process inherited the STDIO streams and has not yet exited.
Full debug logs can be found here
The core content of the forecasts.py
is the following:
import schedule
import time
def job():
print("I'm working...")
schedule.every().minute.at(":00").do(job)
while True:
schedule.run_pending()
time.sleep(5)
This script should print "I'm working..." once per minute. Should I start the script with some different way?
EDIT
azure-pipelines.yml
might help to solve this:
variables:
- name: system.debug
value: true
jobs:
- deployment: fmi_forecasts_deployment
displayName: fmi_forecasts
environment:
name: AnalyticsServices
resourceType: VirtualMachine
strategy:
rolling:
maxParallel: 2 #for percentages, mention as x%
preDeploy:
steps:
- download: current
- script: echo initialize, cleanup, backup, install certs
deploy:
steps:
- checkout: self
- script: sudo apt install python3-pip
displayName: 'Update pip'
- script: python3 -m pip install -r requirements.txt
displayName: 'Install requirements.txt modules'
- script: rsync -a $(Build.SourcesDirectory) /home/ubuntu/$(Build.Repository.Name)/
displayName: 'Sync files to $(Build.Repository.Name)'
- task: Bash@3
inputs:
targetType: 'inline'
script: python3 /home/ubuntu/$(Build.Repository.Name)/s/forecasts.py &
displayName: 'Start the script'
routeTraffic:
steps:
- script: echo routing traffic
postRouteTraffic:
steps:
- script: echo health check post-route traffic
on:
failure:
steps:
- script: echo Restore from backup! This is on failure
success:
steps:
- script: echo Notify! This is on success
EDIT
I edited the forecasts.py
file to print "Sleeping..." every 5 seconds. And when I execute that with nohup python -u /home/ubuntu/$(Build.Repository.Name)/s/forecasts.py &
I will receive the following logs. So, the script works, but when I look the running processes in the VM, there is not any python processes running. The script dies, when the pipeline ends, I assume.