Python 3.10 subprocess error: FileNotFoundError: [Errno 2] No such file or directory: 'pkill'

I am trying to auto-reload celery that is part of a Django application when code changes are detected. I am starting celery with the following management command:


import shlex
import subprocess

from import BaseCommand
from django.utils import autoreload

def restart_celery_worker():
    cmd = "pkill -9 celery"
    cmd = "celery -A my_app.celery_app worker -l info --concurrency=2"

class Command(BaseCommand):
    def handle(self, *args, **options):
        print("Starting celery worker with autoreload...")

I’m seeing the following error:

Starting celery worker with autoreload...
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/", line 1009, in _bootstrap_inner
  File "/usr/local/lib/python3.10/", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/utils/", line 64, in wrapper
    fn(*args, **kwargs)
  File "/code/core/management/commands/", line 14, in restart_celery_worker
  File "/usr/local/lib/python3.10/", line 345, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/lib/python3.10/", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.10/", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pkill'

I started seeing this issue when trying to update to Python 3.10. Here’s the Dockerfile that I’m using:

FROM python:3.10.0-slim-buster

ENV DEBIAN_FRONTEND=noninteractive

RUN mkdir -m 775 /code



RUN python3 -m pip install --upgrade pip setuptools
RUN pip install pipenv
COPY Pipfile ./
RUN pipenv lock --python /usr/local/bin/python
RUN pipenv install --system --deploy --dev

COPY app /code

>Solution :

pkill is part of the procps package which can be installed via:

apt-get update && apt-get install procps

You can confirm that the procps package is not included in the python:3.10.0-slim-buster image via:

$ docker run --rm python:3.10.0-slim-buster dpkg --get-selections | grep procps

This is because the slim image variant does not include the procps package. However, we can confirm that the procps package is included in the buster image:

$ docker run --rm python:3.10.0-buster dpkg --get-selections | grep procps
libprocps7:amd64                install
procps                          install

Leave a Reply