Hello all,
I am newbie here so please let me know if my question not follow all the rules here. I appreciate it.
I have a problem with calling Django command using signal. Here is my code and settings.
signals.py
from django.dispatch import Signal
app_library_number = Signal()
receivers.py
@receiver(post_save, sender=Library)
def app_library_number_handler(sender, instance, *args, **kwargs):
call_command('app_library_number', '--number', instance.number)
The command itself is to run scrapy crawler I present below.
management / commands / app_library_number.py
class Command(BaseCommand):
help = 'Run app_library_number.py'
def add_arguments(self, parser):
parser.add_argument('--number', help='Library Number')
def handle(self, *args, **options):
number = options['number']
process = CrawlerProcess(get_project_settings())
process.crawl(LibraryNumber, number)
process.start()
All works fine if I call the command via shell command as follows:
`python3.11 manage.py app_library_number --number 12345678`
but when I run it via signal in Django I am getting error
Exception Type: ValueError
Exception Value: set_wakeup_fd only works in main thread of the main interpreter
For versions I use Django ver. 4.1.3 with Apache 2.4.57 (with wsgi)
I appreciate any help,
Lexe