does not work anymore in Python 12
The tasks module imports imp in its autodiscover() function. However, this module is deprecated since Python 3.4 and has been completely removed in Python 12.
How to reproduce :
Assuming the appropriate virtual environment is active, enter the worker start command :
$ ./manage.py process_tasks
or
$ python manage.py process_tasks
Observed result :
Assuming the Python used is version 3.12 or later, this immediately generates an exception :
File "/home/eric/.pyenv/versions/3.12.0/envs/am-resa/lib/python3.12/site-packages/background_task/tasks.py", line 309, in autodiscover
import imp
ModuleNotFoundError: No module named 'imp'
The official Python documentation states that module imp is now replaced by importlib. This can be found since version 3.4 and up to version 3.11. The imp module does not exist anymore in version 3.12 documentation.
Maybe some patch similar to this one would work:
From: Jochen Sprickerhof <git@redacted>
Date: Wed, 22 Nov 2023 17:34:35 +0100
Subject: Replace imp by importlib for Python 3.12
---
setup.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/setup.py b/setup.py
index 0e07668..44ced26 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
from setuptools import setup
-import imp
+import importlib
with open('README.rst') as readme_file:
README = readme_file.read()
@@ -8,8 +8,9 @@ with open('README.rst') as readme_file:
def get_version():
ver_file = None
try:
- ver_file, pathname, description = imp.find_module('__version__', ['src/vcstools'])
- vermod = imp.load_module('__version__', ver_file, pathname, description)
+ spec = importlib.util.spec_from_file_location('__version__', 'src/vcstools/__version__.py')
+ vermod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(vermod)
version = vermod.version
return version
finally:
I have been maintaining an updated package for a couple years now. Updated recently with 3.12 support. https://pypi.org/project/django-background-tasks-updated/
@iamjonmiller, are you interested in maintaining the project? I would also consider moving it to https://github.com/django-background-tasks.
@philippeowagner I'm happy to maintain the project!
@iamjonmiller I've emailed you.