Skip to content

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

added --pidfile option

olveyrae11d824ed0bb
diff --git a/scrapy/trunk/scrapy/command/models.py b/scrapy/trunk/scrapy/command/models.py
index 57ea715e2..cb1aa1539 100644
--- a/scrapy/trunk/scrapy/command/models.py
+++ b/scrapy/trunk/scrapy/command/models.py
@@ -1,6 +1,7 @@
"""
Base class for Scrapy commands
"""
+import os
from scrapy.conf import settings
class ScrapyCommand(object):
@@ -41,7 +42,8 @@ class ScrapyCommand(object):
parser.add_option("--spider", dest="spider", default=None, help="default spider (domain) to use if no spider is found")
parser.add_option("--nolog", dest="nolog", action="store_true", help="disable all log messages")
parser.add_option("--profile", dest="profile", default=None, help="write profiling stats in FILE, to analyze later with: python -m pstats FILE", metavar="FILE")
-
+ parser.add_option("--pidfile", dest="pidfile", help="Write process pid to file FILE", metavar="FILE")
+
def process_options(self, args, opts):
if opts.logfile:
settings.overrides['LOG_ENABLED'] = True
@@ -58,6 +60,10 @@ class ScrapyCommand(object):
from scrapy.spider import spiders
spiders.default_domain = opts.spider
+ if opts.pidfile:
+ pid = os.getpid()
+ open(opts.pidfile, "w").write(str(pid))
+
def run(self, args, opts):
"""
Entry point for running commands