Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Improve signal sending in test_shutdown_forced.

Andrey Rakhmatullin6b0c18e921c0
diff --git a/tests/test_crawler.py b/tests/test_crawler.py
index 5c11ca6e0..0a7f9bac8 100644
--- a/tests/test_crawler.py
+++ b/tests/test_crawler.py
@@ -534,7 +534,10 @@ class CrawlerProcessSubprocess(ScriptRunnerMixin, unittest.TestCase):
p.expect_exact("Spider closed (shutdown)")
p.wait()
+ @defer.inlineCallbacks
def test_shutdown_forced(self):
+ from twisted.internet import reactor
+
sig = signal.SIGINT if sys.platform != "win32" else signal.SIGBREAK
args = self.get_script_args("sleeping.py", "-a", "sleep=10")
p = PopenSpawn(args, timeout=5)
@@ -542,6 +545,10 @@ class CrawlerProcessSubprocess(ScriptRunnerMixin, unittest.TestCase):
p.expect_exact("Crawled (200)")
p.kill(sig)
p.expect_exact("shutting down gracefully")
+ # sending the second signal too fast often causes problems
+ d = defer.Deferred()
+ reactor.callLater(0.1, d.callback, None)
+ yield d
p.kill(sig)
p.expect_exact("forcing unclean shutdown")
p.wait()