• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

293
Views
Docker Continuar para ejecutar el proceso en segundo plano incluso después de matar

Estoy usando la ventana acoplable para ejecutar un script de python que usa el módulo de subprocess para ejecutar algunos comandos en la terminal,

Después de ejecutar el script usando la ventana acoplable, si uso ctrl+c o el comando kill para matar el proceso, en mi terminal el proceso se está matando, pero el proceso continúa ejecutándose en segundo plano y crea registros también.

Intenté ejecutar el script directamente en mi sistema, y funciona bien y después de matarlo simplemente se detiene, pero cuando ejecuté usando la ventana acoplable, continuó ejecutándose en segundo plano incluso después de kill -9 process_id .

código de muestra para simular el problema.

 import getpass import subprocess import os import signal, time print('python user: ', getpass.getuser()) def test(i): try: drop_temp_tbl = subprocess.Popen(f'echo "test">>test.txt;sleep 40; echo "test6{i}">>test.txt;', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (drop_temp_tbl_stdout, drop_temp_tbl_stderr) = drop_temp_tbl.communicate() print('_subprocess_user,', drop_temp_tbl_stdout, '\n', drop_temp_tbl_stderr) except Exception as e: print('terminate ',os.killpg(os.getpgid(drop_temp_tbl.pid), signal.SIGTERM) ) print('ERROR', e) for i in range(2): test(i)

Comando de ejecución de Docker

docker run -i --rm -v `pwd`:/code ${docker_id} python_script.py

Dockerfile

 FROM ubuntu:latest RUN apt-get update && \ apt-get install -yf software-properties-common RUN apt-get -yq update && \ apt-get -yqq install \ openssh-client COPY ./docker_requirement ./ RUN pip install --no-cache-dir -r docker_requirement RUN groupadd --gid 1000 app RUN useradd --uid 1000 --gid app --home /app app USER 1000 ADD . /code WORKDIR /code ENTRYPOINT ["python3"]

para el ejemplo anterior, ejecutar a través de Docker continuará test.txt incluso después de kill -9 process_id

about 3 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error