[Python] The celery process managed by supervisor cannot correctly identify the mysql package

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    environment:
    salt 3007.1 (Chlorine) (Install using yum)
    supervisor 4.2.2 (Install using yum)

    python 3.9.18 (Install using pyenv)
    salt 3007.1 (Install using pip)
    celery 5.3.6 (Install using pip)
    mysqlclient 2.2.4 (Install using pip)


    When I use salt.client in a virtual environment (with mysql configured as returner), the following error message appears. After testing, I found that the mysql package must be installed not only in the saltstack environment, but also in the current virtual environment when calling salt.client in another virtual environment.

    After I install the MySQL package in the virtual environment, I enter the virtual environment directly in the command line and execute any Salt command without the following error.

    Then I used supervisor to manage the celery task, and each time the task was executed, I found the following error.

    [2025-05-26 11:06:21,706: ERROR/ForkPoolWorker-31] Exception raised when processing __virtual__ function for salt.loaded.int.module.vmctl. Module will not be loaded: 'os'
    [2025-05-26 11:06:21,706: WARNING/ForkPoolWorker-31] salt.loaded.int.module.vmctl.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module 'vmctl', please fix this.
    [2025-05-26 11:06:21,836: ERROR/ForkPoolWorker-31] Exception raised when processing __virtual__ function for salt.loaded.int.module.xapi_virt. Module will not be loaded: 'os'
    [2025-05-26 11:06:21,836: WARNING/ForkPoolWorker-31] salt.loaded.int.module.xapi_virt.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module 'xapi_virt', please fix this.
    [2025-05-26 11:06:21,837: ERROR/ForkPoolWorker-31] Exception raised when processing __virtual__ function for salt.loaded.int.module.xbpspkg. Module will not be loaded: 'os'
    [2025-05-26 11:06:21,837: WARNING/ForkPoolWorker-31] salt.loaded.int.module.xbpspkg.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module 'xbpspkg', please fix this.
    [2025-05-26 11:06:21,849: ERROR/ForkPoolWorker-31] Exception raised when processing __virtual__ function for salt.loaded.int.module.zoneadm. Module will not be loaded: 'kernel'
    [2025-05-26 11:06:21,849: WARNING/ForkPoolWorker-31] salt.loaded.int.module.zoneadm.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module 'zoneadm', please fix this.
    [2025-05-26 11:06:21,850: ERROR/ForkPoolWorker-31] Exception raised when processing __virtual__ function for salt.loaded.int.module.zonecfg. Module will not be loaded: 'kernel'
    [2025-05-26 11:06:21,850: WARNING/ForkPoolWorker-31] salt.loaded.int.module.zonecfg.__virtual__() is wrongly returning `None`. It should either return `True`, `False` or a new name. If you're the developer of the module 'zonecfg', please fix this.
    [2025-05-26 11:06:21,884: WARNING/ForkPoolWorker-31] Returner unavailable: 'mysql.get_load'


    I tried to print the following information in the task, and the output all looks correct

    logger.warning("Python executable: %s", sys.executable)
    logger.warning("sys.path: %s", sys.path)

    [2025-05-26 11:06:18] [djapps.exec] [ForkPoolWorker-31:MainThread] [tasks.py:ha_manage_v1:49] WARNING - Python executable: /home/test/.pyenv/versions/testtask/bin/python3.9
    [2025-05-26 11:06:18] [djapps.exec] [ForkPoolWorker-31:MainThread] [tasks.py:ha_manage_v1:50] WARNING - sys.path: ['/home/test/Projects/testtask', '/home/test/.pyenv/versions/3.9.18/envs/testtask/bin', '/home/test/.pyenv/versions/3.9.18/envs/testtask/lib/python3.9/site-packages', '/home/test/.pyenv/versions/3.9.18/lib/python39.zip', '/home/test/.pyenv/versions/3.9.18/lib/python3.9', '/home/test/.pyenv/versions/3.9.18/lib/python3.9/lib-dynload', '/home/test/.pyenv/versions/testtask/lib/python3.9/site-packages']


    My configuration file initially looked like this:

    [program:test_worker]
    command=celery -A testtask worker -l info -Q test_worker
    directory=/home/test/Projects/testtask
    user=test
    startsecs=5
    startretries=3
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile_maxbytes=0
    stdout_logfile_backups=0
    stdout_logfile=/var/log/supervisor/test_worker.log

    environment=PATH="/home/test/.pyenv/versions/testtask/bin:%(ENV_PATH)s"


    I later adjusted it to this:

    [program:test_worker]
    command=/home/test/.pyenv/versions/3.9.18/envs/testtask/bin/celery -A testtask worker -l info -Q test_worker
    directory=/home/test/Projects/testtask
    user=test
    startsecs=5
    startretries=3
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile_maxbytes=0
    stdout_logfile_backups=0
    stdout_logfile=/var/log/supervisor/test_worker.log

    environment=PATH="/home/test/.pyenv/versions/3.9.18/envs/testtask/bin:%(ENV_PATH)s",VIRTUAL_ENV="/home/test/.pyenv/versions/3.9.18/envs/testtask",PYTHONPATH="/home/test/.pyenv/versions/3.9.18/envs/testtask/lib/python3.9/site-packages/"


    But it doesn't work, it still prompts that the mysql package cannot be imported. Can anyone help me find the cause of the problem? I am sure that the package is installed, but it cannot be imported in Supervisor Management.

    Continue reading...

Compartilhe esta Página