Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:32:31+00:00 2026-06-08T10:32:31+00:00

I have a Django site where a scrape happens when a user requests it,

  • 0

I have a Django site where a scrape happens when a user requests it, and my code kicks off a Scrapy spider standalone script in a new process. Naturally, this isn’t working with an increase of users.

Something like this:

class StandAloneSpider(Spider):
    #a regular spider

settings.overrides['LOG_ENABLED'] = True
#more settings can be changed...

crawler = CrawlerProcess( settings )
crawler.install()
crawler.configure()

spider = StandAloneSpider()

crawler.crawl( spider )
crawler.start()

I’ve decided to use Celery and use workers to queue up the crawl requests.

However, I’m running into issues with Tornado reactors not being able to restart. The first and second spider runs successfully, but subsequent spiders will throw the ReactorNotRestartable error.

Anyone can share any tips with running Spiders within the Celery framework?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:32:34+00:00Added an answer on June 8, 2026 at 10:32 am

    Okay here is how I got Scrapy working with my Django project that uses Celery for queuing up what to crawl. The actual workaround came primarily from joehillen’s code located here http://snippets.scrapy.org/snippets/13/

    First the tasks.py file

    from celery import task
    
    @task()
    def crawl_domain(domain_pk):
        from crawl import domain_crawl
        return domain_crawl(domain_pk)
    

    Then the crawl.py file

    from multiprocessing import Process
    from scrapy.crawler import CrawlerProcess
    from scrapy.conf import settings
    from spider import DomainSpider
    from models import Domain
    
    class DomainCrawlerScript():
    
        def __init__(self):
            self.crawler = CrawlerProcess(settings)
            self.crawler.install()
            self.crawler.configure()
    
        def _crawl(self, domain_pk):
            domain = Domain.objects.get(
                pk = domain_pk,
            )
            urls = []
            for page in domain.pages.all():
                urls.append(page.url())
            self.crawler.crawl(DomainSpider(urls))
            self.crawler.start()
            self.crawler.stop()
    
        def crawl(self, domain_pk):
            p = Process(target=self._crawl, args=[domain_pk])
            p.start()
            p.join()
    
    crawler = DomainCrawlerScript()
    
    def domain_crawl(domain_pk):
        crawler.crawl(domain_pk)
    

    The trick here is the “from multiprocessing import Process” this gets around the “ReactorNotRestartable” issue in the Twisted framework. So basically the Celery task calls the “domain_crawl” function which reuses the “DomainCrawlerScript” object over and over to interface with your Scrapy spider. (I am aware that my example is a little redundant but I did do this for a reason in my setup with multiple versions of python [my django webserver is actually using python2.4 and my worker servers use python2.7])

    In my example here “DomainSpider” is just a modified Scrapy Spider that takes a list of urls in then sets them as the “start_urls”.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django server that serves the basic site with user, auth etc
I have an existing PostgreSQL database that I'm using for a new Django site.
I'm new to both Django and Cappuccino. I have a Django site setup and
I have a django site where I need to call a script using subprocess.
I am having problems with user authentication for my django site. I have a
I have a Django site that takes in sensitive information. I use https/SSL, so
I have a django site using the basic django registration framework. I have my
I currently have a django site, and it's kind of slow, so I want
I have a similar question than django cross-site reverse . But i think I
I have enabled site-wide Django caching , but the third-party apps I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.