0

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)
Maximilian Jesch
  • 623
  • 7
  • 16
  • 1
    there are several ways to go about this, but the one closest to what you ask for is nicely described [here](https://stackoverflow.com/a/636570/9267296) – Edo Akse Mar 21 '22 at 13:26

1 Answers1

0

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())
SCcagg5
  • 576
  • 3
  • 15