prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Exception when using DummyStatsCollector
  ### Description
  
  Using the DummyStatsCollector results in an exception:
  
  ```
  2019-09-09 13:51:23 [scrapy.utils.signal] ERROR: Error caught on signal handler: <bound method CoreStats.spider_closed of <scrapy.extensions.corestats.CoreStats object at 0x7f86269cac18>>
  Traceback (most recent call last):
    File ".../lib/python3.6/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
      result = f(*args, **kw)
    File ".../lib/python3.6/site-packages/pydispatch/robustapply.py", line 55, in robustApply
      return receiver(*arguments, **named)
    File ".../lib/python3.6/site-packages/scrapy/extensions/corestats.py", line 28, in spider_closed
      elapsed_time = finish_time - self.stats.get_value('start_time')
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'
  ```
  
  This problem has been introduced in aa46e1995cd5cb1099aba17535372b538bd656b3.
  
  ### Steps to Reproduce
  
  Set `STATS_CLASS = "scrapy.statscollectors.DummyStatsCollector"` in the settings module as described in the documentation (https://docs.scrapy.org/en/latest/topics/stats.html#dummystatscollector).
  
  **Expected behavior:** no exception
  **Actual behavior:** exception thrown
  **Reproduces how often:** always
  
  ### Versions
  
  At least master as of 534de7395da3a53b5a2c89960db9ec5d8fdab60c
  
  ### Fix
  
  A possible fix is to use the elapsed time as a default argument so that `get_value()` does not return None. I can prepare a PR if needed.
  
  ```diff
  --- a/scrapy/extensions/corestats.py
  +++ b/scrapy/extensions/corestats.py
  @@ -25,7 +25,7 @@ class CoreStats(object):
   
       def spider_closed(self, spider, reason):
           finish_time = datetime.datetime.utcnow()
  -        elapsed_time = finish_time - self.stats.get_value('start_time')
  +        elapsed_time = finish_time - self.stats.get_value('start_time', finish_time)
           elapsed_time_seconds = elapsed_time.total_seconds()
           self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)
           self.stats.set_value('finish_time', finish_time, spider=spider)
  ```
  
  </issue>
  <code>
  [start of scrapy/extensions/corestats.py]
  1 """
  2 Extension for collecting core stats like items scraped and start/finish times
  3 """
  4 import datetime
  5 
  6 from scrapy import signals
  7 
  8 class CoreStats(object):
  9 
  10     def __init__(self, stats):
  11         self.stats = stats
  12 
  13     @classmethod
  14     def from_crawler(cls, crawler):
  15         o = cls(crawler.stats)
  16         crawler.signals.connect(o.spider_opened, signal=signals.spider_opened)
  17         crawler.signals.connect(o.spider_closed, signal=signals.spider_closed)
  18         crawler.signals.connect(o.item_scraped, signal=signals.item_scraped)
  19         crawler.signals.connect(o.item_dropped, signal=signals.item_dropped)
  20         crawler.signals.connect(o.response_received, signal=signals.response_received)
  21         return o
  22 
  23     def spider_opened(self, spider):
  24         self.stats.set_value('start_time', datetime.datetime.utcnow(), spider=spider)
  25 
  26     def spider_closed(self, spider, reason):
  27         finish_time = datetime.datetime.utcnow()
  28         elapsed_time = finish_time - self.stats.get_value('start_time')
  29         elapsed_time_seconds = elapsed_time.total_seconds()
  30         self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)
  31         self.stats.set_value('finish_time', finish_time, spider=spider)
  32         self.stats.set_value('finish_reason', reason, spider=spider)
  33 
  34     def item_scraped(self, item, spider):
  35         self.stats.inc_value('item_scraped_count', spider=spider)
  36 
  37     def response_received(self, spider):
  38         self.stats.inc_value('response_received_count', spider=spider)
  39 
  40     def item_dropped(self, item, spider, exception):
  41         reason = exception.__class__.__name__
  42         self.stats.inc_value('item_dropped_count', spider=spider)
  43         self.stats.inc_value('item_dropped_reasons_count/%s' % reason, spider=spider)
  44
  [end of scrapy/extensions/corestats.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/scrapy/extensions/corestats.py b/scrapy/extensions/corestats.py
  --- a/scrapy/extensions/corestats.py
  +++ b/scrapy/extensions/corestats.py
  @@ -1,14 +1,16 @@
   """
   Extension for collecting core stats like items scraped and start/finish times
   """
  -import datetime
  +from datetime import datetime
   
   from scrapy import signals
   
  +
   class CoreStats(object):
   
       def __init__(self, stats):
           self.stats = stats
  +        self.start_time = None
   
       @classmethod
       def from_crawler(cls, crawler):
  @@ -21,11 +23,12 @@
           return o
   
       def spider_opened(self, spider):
  -        self.stats.set_value('start_time', datetime.datetime.utcnow(), spider=spider)
  +        self.start_time = datetime.utcnow()
  +        self.stats.set_value('start_time', self.start_time, spider=spider)
   
       def spider_closed(self, spider, reason):
  -        finish_time = datetime.datetime.utcnow()
  -        elapsed_time = finish_time - self.stats.get_value('start_time')
  +        finish_time = datetime.utcnow()
  +        elapsed_time = finish_time - self.start_time
           elapsed_time_seconds = elapsed_time.total_seconds()
           self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)
           self.stats.set_value('finish_time', finish_time, spider=spider)
  
verification_info: {"golden_diff": "diff --git a/scrapy/extensions/corestats.py b/scrapy/extensions/corestats.py\n--- a/scrapy/extensions/corestats.py\n+++ b/scrapy/extensions/corestats.py\n@@ -1,14 +1,16 @@\n \"\"\"\n Extension for collecting core stats like items scraped and start/finish times\n \"\"\"\n-import datetime\n+from datetime import datetime\n \n from scrapy import signals\n \n+\n class CoreStats(object):\n \n     def __init__(self, stats):\n         self.stats = stats\n+        self.start_time = None\n \n     @classmethod\n     def from_crawler(cls, crawler):\n@@ -21,11 +23,12 @@\n         return o\n \n     def spider_opened(self, spider):\n-        self.stats.set_value('start_time', datetime.datetime.utcnow(), spider=spider)\n+        self.start_time = datetime.utcnow()\n+        self.stats.set_value('start_time', self.start_time, spider=spider)\n \n     def spider_closed(self, spider, reason):\n-        finish_time = datetime.datetime.utcnow()\n-        elapsed_time = finish_time - self.stats.get_value('start_time')\n+        finish_time = datetime.utcnow()\n+        elapsed_time = finish_time - self.start_time\n         elapsed_time_seconds = elapsed_time.total_seconds()\n         self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)\n         self.stats.set_value('finish_time', finish_time, spider=spider)\n", "issue": "Exception when using DummyStatsCollector\n### Description\r\n\r\nUsing the DummyStatsCollector results in an exception:\r\n\r\n```\r\n2019-09-09 13:51:23 [scrapy.utils.signal] ERROR: Error caught on signal handler: <bound method CoreStats.spider_closed of <scrapy.extensions.corestats.CoreStats object at 0x7f86269cac18>>\r\nTraceback (most recent call last):\r\n  File \".../lib/python3.6/site-packages/twisted/internet/defer.py\", line 150, in maybeDeferred\r\n    result = f(*args, **kw)\r\n  File \".../lib/python3.6/site-packages/pydispatch/robustapply.py\", line 55, in robustApply\r\n    return receiver(*arguments, **named)\r\n  File \".../lib/python3.6/site-packages/scrapy/extensions/corestats.py\", line 28, in spider_closed\r\n    elapsed_time = finish_time - self.stats.get_value('start_time')\r\nTypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'\r\n```\r\n\r\nThis problem has been introduced in aa46e1995cd5cb1099aba17535372b538bd656b3.\r\n\r\n### Steps to Reproduce\r\n\r\nSet `STATS_CLASS = \"scrapy.statscollectors.DummyStatsCollector\"` in the settings module as described in the documentation (https://docs.scrapy.org/en/latest/topics/stats.html#dummystatscollector).\r\n\r\n**Expected behavior:** no exception\r\n**Actual behavior:** exception thrown\r\n**Reproduces how often:** always\r\n\r\n### Versions\r\n\r\nAt least master as of 534de7395da3a53b5a2c89960db9ec5d8fdab60c\r\n\r\n### Fix\r\n\r\nA possible fix is to use the elapsed time as a default argument so that `get_value()` does not return None. I can prepare a PR if needed.\r\n\r\n```diff\r\n--- a/scrapy/extensions/corestats.py\r\n+++ b/scrapy/extensions/corestats.py\r\n@@ -25,7 +25,7 @@ class CoreStats(object):\r\n \r\n     def spider_closed(self, spider, reason):\r\n         finish_time = datetime.datetime.utcnow()\r\n-        elapsed_time = finish_time - self.stats.get_value('start_time')\r\n+        elapsed_time = finish_time - self.stats.get_value('start_time', finish_time)\r\n         elapsed_time_seconds = elapsed_time.total_seconds()\r\n         self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)\r\n         self.stats.set_value('finish_time', finish_time, spider=spider)\r\n```\n", "before_files": [{"content": "\"\"\"\nExtension for collecting core stats like items scraped and start/finish times\n\"\"\"\nimport datetime\n\nfrom scrapy import signals\n\nclass CoreStats(object):\n\n    def __init__(self, stats):\n        self.stats = stats\n\n    @classmethod\n    def from_crawler(cls, crawler):\n        o = cls(crawler.stats)\n        crawler.signals.connect(o.spider_opened, signal=signals.spider_opened)\n        crawler.signals.connect(o.spider_closed, signal=signals.spider_closed)\n        crawler.signals.connect(o.item_scraped, signal=signals.item_scraped)\n        crawler.signals.connect(o.item_dropped, signal=signals.item_dropped)\n        crawler.signals.connect(o.response_received, signal=signals.response_received)\n        return o\n\n    def spider_opened(self, spider):\n        self.stats.set_value('start_time', datetime.datetime.utcnow(), spider=spider)\n\n    def spider_closed(self, spider, reason):\n        finish_time = datetime.datetime.utcnow()\n        elapsed_time = finish_time - self.stats.get_value('start_time')\n        elapsed_time_seconds = elapsed_time.total_seconds()\n        self.stats.set_value('elapsed_time_seconds', elapsed_time_seconds, spider=spider)\n        self.stats.set_value('finish_time', finish_time, spider=spider)\n        self.stats.set_value('finish_reason', reason, spider=spider)\n\n    def item_scraped(self, item, spider):\n        self.stats.inc_value('item_scraped_count', spider=spider)\n\n    def response_received(self, spider):\n        self.stats.inc_value('response_received_count', spider=spider)\n\n    def item_dropped(self, item, spider, exception):\n        reason = exception.__class__.__name__\n        self.stats.inc_value('item_dropped_count', spider=spider)\n        self.stats.inc_value('item_dropped_reasons_count/%s' % reason, spider=spider)\n", "path": "scrapy/extensions/corestats.py"}]}