'Run python script headless to execute in fixed timeinterval independent of duration of execution

I have a simple python script that records 10 minutes of video and then sends the resulting file to an azure blob storage. I want to put it in a docker image and have it run in a kubernetes cluster. I want to set it up in a way that I have (almost) everything recorded (a few seconds missing between recordings dont matter). The obvious problem is that the "send file to storage" part takes a significant amount of time, depending on the network connection. Is there a way to run python in a headless mode so I can do something like that:

#!/bin/bash
while true
do
    python3 --headless record_video.py
    sleep 10
done

UPDATE: The solution that worked for me was not solving it on "shell level" but ruther on python level using a subprocess that spawns new shells:

import time
from subprocess import Popen
while True:
    p = Popen('python video_recording_main.py -u -p -vd 1', shell=True)
    time.sleep(60)


Solution 1:[1]

You could use asyncio which is very basic

Here is an exemple (python 3.7+):

import asyncio
import time
async def say_after(delay, what):
  await asyncio.sleep(delay)
  print(what)

async def main():
  tasks = []
  words = ['hello', 'world']
  for word in words:
    tasks.append(say_after(1, word))
  for task in tasks:
    await task
asyncio.run(main())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SCcagg5