Reputation: 1
I'm testing Django-Q to improve my project, which involves sending study certificates. However, I'm encountering an issue. The log shows the following error:
File "C:\Python311\Lib\multiprocessing\queues.py", line 244, in _feed obj = _ForkingPickler.dumps(obj)
File "C:\Python311\Lib\multiprocessing\reduction.py", line 51, in dumps cls(buf, protocol).dump(obj) TypeError: cannot pickle '_thread.RLock' object
When this error appears, it starts an infinite loop that sends emails with the attached file about the certificates. I suspect that I've made a mistake somewhere, so any help would be greatly appreciated!
Here is the code in my tasks.py:
from django.core.mail import EmailMessage from django_q.tasks import async_task
def send_email_task(subject, message, recipient_list, attachments=None): """ Sends an email asynchronously. """ email = EmailMessage(subject, message, '[email protected]', recipient_list) if attachments: for attachment in attachments: email.attach(*attachment)
async_task(email.send, fail_silently=False)
Here my admin.py: def generate_pdf(self, request, queryset): constancia_id = queryset.values_list('id', flat=True)[0]
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="constancia.pdf"'
#Code for the content in the file
# Call the function from tasks.py
send_email_task(
"Constancia de Estudios",
f'Hola {primer_nombre} {primer_apellido}, tu solicitud de constancia de estudio ha sido exitosa. '
'Por favor revisa el archivo adjunto para obtener tu constancia de estudio',
[correo],
attachments=[(f'constancia_{primer_nombre}_{primer_apellido}.pdf', response.getvalue(), 'application/pdf')]
)
self.message_user(request, "Constancia generada y enviada por correo exitosamente.")
return response
generate_pdf.short_description = "Descarga los items como PDF"
I hope someone can help me resolve this issue so I can continue with my project. I need to send emails quickly and use an asynchronous connection. Thanks in advance!
Upvotes: 0
Views: 25