Scrapy, a fast high-level web crawling & scraping framework for Python.
added Debugger extension, removed StackTraceDump from extensions available by default
Pablo Hoffman269724a2b7c7
diff --git a/docs/topics/extensions.rst b/docs/topics/extensions.rstindex abebb5d29..806a5d63a 100644--- a/docs/topics/extensions.rst+++ b/docs/topics/extensions.rst@@ -40,7 +40,6 @@ by a string: the full Python path to the extension's class name. For example::'scrapy.management.telnet.TelnetConsole': 500,'scrapy.contrib.webconsole.enginestatus.EngineStatus': 500,'scrapy.contrib.webconsole.stats.StatsDump': 500,- 'scrapy.contrib.debug.StackTraceDump': 500,}@@ -112,15 +111,10 @@ everytime a domain/spider is opened and closed::log.msg("closed domain %s" % domain)-.. _topics-extensions-ref:--Built-in extensions reference-=============================-.. _topics-extensions-ref-manager:Extension manager------------------+=================.. module:: scrapy.extension:synopsis: The extension manager@@ -179,6 +173,12 @@ how you :ref:`configure the downloader middlewaresReload the available extensions. See :meth:`load`.++.. _topics-extensions-ref:++Built-in extensions reference+=============================+General purpose extensions--------------------------@@ -312,25 +312,6 @@ that amount if items and those items are passed by the item pipeline, thedomain will be closed with the reason ``closedomain_itempassed``. If zero (ornon set) domains won't be closed by number of passed items.-Stack trace dump extension-~~~~~~~~~~~~~~~~~~~~~~~~~~--.. module:: scrapy.contrib.debug- :synopsis: Extensions for debugging Scrapy--.. class:: scrapy.contrib.debug.StackTraceDump--Adds a `SIGUSR1`_ signal handler which dumps the stack trace of a runnning-Scrapy process when a ``SIGUSR1`` signal is catched. After the stack trace is-dumped, the Scrapy process continues to run normally.--The stack trace is sent to standard output, or to the Scrapy log file if-:setting:`LOG_STDOUT` is enabled.--This extension only works on POSIX-compliant platforms (ie. not Windows).--.. _SIGUSR1: http://en.wikipedia.org/wiki/SIGUSR1_and_SIGUSR2-StatsMailer extension~~~~~~~~~~~~~~~~~~~~~@@ -344,6 +325,7 @@ domain has finished scraping, including the Scrapy stats collected. The emailwill be sent to all recipients specified in the :setting:`STATSMAILER_RCPTS`setting.+Web console extensions----------------------@@ -405,3 +387,40 @@ Stats collector dump WC extensionDisplay the stats collected so far by the stats collector.++.. module:: scrapy.contrib.debug+ :synopsis: Extensions for debugging Scrapy++Debugging extensions+--------------------++Stack trace dump extension+~~~~~~~~~~~~~~~~~~~~~~~~~~++.. class:: scrapy.contrib.debug.StackTraceDump++Dumps the stack trace of a runnning Scrapy process when a `SIGUSR2`_ signal is+received. After the stack trace is dumped, the Scrapy process continues running+normally.++The stack trace is sent to standard output.++This extension only works on POSIX-compliant platforms (ie. not Windows).++.. _SIGUSR2: http://en.wikipedia.org/wiki/SIGUSR1_and_SIGUSR2++Debugger extension+~~~~~~~~~~~~~~~~~~++.. class:: scrapy.contrib.debug.Debugger++Invokes a `Python debugger`_ inside a running Scrapy process when a `SIGUSR2`_+signal is received. After the debugger is exited, the Scrapy process continues+running normally.++For more info see `Debugging in Python`.++This extension only works on POSIX-compliant platforms (ie. not Windows).++.. _Python debugger: http://docs.python.org/library/pdb.html+.. _Debugging in Python: http://www.ferg.org/papers/debugging_in_python.htmldiff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex f742b97f3..bf5fdfceb 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -495,7 +495,6 @@ Default::'scrapy.contrib.memusage.MemoryUsage': 0,'scrapy.contrib.memdebug.MemoryDebugger': 0,'scrapy.contrib.closedomain.CloseDomain': 0,- 'scrapy.contrib.debug.StackTraceDump': 0,}The list of available extensions. Keep in mind that some of them need need todiff --git a/scrapy/conf/default_settings.py b/scrapy/conf/default_settings.pyindex ad82f34fc..890fb11c6 100644--- a/scrapy/conf/default_settings.py+++ b/scrapy/conf/default_settings.py@@ -84,7 +84,6 @@ EXTENSIONS_BASE = {'scrapy.contrib.memusage.MemoryUsage': 0,'scrapy.contrib.memdebug.MemoryDebugger': 0,'scrapy.contrib.closedomain.CloseDomain': 0,- 'scrapy.contrib.debug.StackTraceDump': 0,}GROUPSETTINGS_ENABLED = Falsediff --git a/scrapy/contrib/debug.py b/scrapy/contrib/debug.pyindex 9a4fa9764..27048efe2 100644--- a/scrapy/contrib/debug.py+++ b/scrapy/contrib/debug.py@@ -3,8 +3,11 @@ Extensions for debugging ScrapySee documentation in docs/topics/extensions.rst"""+import signalimport traceback+from pdb import Pdb+class StackTraceDump(object):def __init__(self):@@ -17,3 +20,15 @@ class StackTraceDump(object):def dump_stacktrace(self, signum, frame):print "Got signal. Dumping stack trace..."traceback.print_stack(frame)+++class Debugger(object):+ def __init__(self):+ try:+ signal.signal(signal.SIGUSR2, self._enter_debugger)+ except AttributeError:+ # win32 platforms don't support SIGUSR signals+ pass++ def _enter_debugger(self, signum, frame):+ Pdb().set_trace(frame.f_back)