prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add ability to keep retrying with a lock error
  The yum installer (IIRC) has a nice feature that it will keep trying every 10 seconds or so if there is a lock error. This could be useful for conda. 
  
  
  </issue>
  <code>
  [start of conda/lock.py]
  1 # (c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io
  2 # All Rights Reserved
  3 #
  4 # conda is distributed under the terms of the BSD 3-clause license.
  5 # Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.
  6 
  7 """
  8 Tools for working with locks
  9 
  10 A lock is just an empty directory. We use directories because this lets us use
  11 the race condition-proof os.makedirs.
  12 
  13 For now, there is one global lock for all of conda, because some things happen
  14 globally (such as downloading packages).
  15 
  16 We don't raise an error if the lock is named with the current PID
  17 """
  18 
  19 import os
  20 from os.path import join
  21 import glob
  22 
  23 
  24 LOCKFN = '.conda_lock'
  25 
  26 
  27 class Locked(object):
  28     """
  29     Context manager to handle locks.
  30     """
  31     def __init__(self, path):
  32         self.path = path
  33         self.end = "-" + str(os.getpid())
  34         self.lock_path = join(self.path, LOCKFN + self.end)
  35         self.pattern = join(self.path, LOCKFN + '-*')
  36         self.remove = True
  37 
  38     def __enter__(self):
  39         files = glob.glob(self.pattern)
  40         if files and not files[0].endswith(self.end):
  41             # Keep the string "LOCKERROR" in this string so that external
  42             # programs can look for it.
  43             raise RuntimeError("""\
  44 LOCKERROR: It looks like conda is already doing something.
  45 The lock %s was found. Wait for it to finish before continuing.
  46 If you are sure that conda is not running, remove it and try again.
  47 You can also use: $ conda clean --lock""" % self.lock_path)
  48 
  49         if not files:
  50             try:
  51                 os.makedirs(self.lock_path)
  52             except OSError:
  53                 pass
  54         else: # PID lock already here --- someone else will remove it.
  55             self.remove = False
  56 
  57     def __exit__(self, exc_type, exc_value, traceback):
  58         if self.remove:
  59             for path in self.lock_path, self.path:
  60                 try:
  61                     os.rmdir(path)
  62                 except OSError:
  63                     pass
  64
  [end of conda/lock.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/conda/lock.py b/conda/lock.py
  --- a/conda/lock.py
  +++ b/conda/lock.py
  @@ -19,7 +19,7 @@
   import os
   from os.path import join
   import glob
  -
  +from time import sleep
   
   LOCKFN = '.conda_lock'
   
  @@ -36,15 +36,28 @@
           self.remove = True
   
       def __enter__(self):
  -        files = glob.glob(self.pattern)
  -        if files and not files[0].endswith(self.end):
  -            # Keep the string "LOCKERROR" in this string so that external
  -            # programs can look for it.
  -            raise RuntimeError("""\
  -LOCKERROR: It looks like conda is already doing something.
  -The lock %s was found. Wait for it to finish before continuing.
  -If you are sure that conda is not running, remove it and try again.
  -You can also use: $ conda clean --lock""" % self.lock_path)
  +        retries = 10
  +        # Keep the string "LOCKERROR" in this string so that external
  +        # programs can look for it.
  +        lockstr = ("""\
  +    LOCKERROR: It looks like conda is already doing something.
  +    The lock %s was found. Wait for it to finish before continuing.
  +    If you are sure that conda is not running, remove it and try again.
  +    You can also use: $ conda clean --lock""" % self.lock_path)
  +        sleeptime = 1
  +        while retries:
  +            files = glob.glob(self.pattern)
  +            if files and not files[0].endswith(self.end):
  +                print(lockstr)
  +                print("Sleeping for %s seconds" % sleeptime)
  +                sleep(sleeptime)
  +                sleeptime *= 2
  +                retries -= 1
  +            else:
  +                break
  +        else:
  +            print("Exceeded max retries, giving up")
  +            raise RuntimeError(lockstr)
   
           if not files:
               try:
  
verification_info: {"golden_diff": "diff --git a/conda/lock.py b/conda/lock.py\n--- a/conda/lock.py\n+++ b/conda/lock.py\n@@ -19,7 +19,7 @@\n import os\n from os.path import join\n import glob\n-\n+from time import sleep\n \n LOCKFN = '.conda_lock'\n \n@@ -36,15 +36,28 @@\n         self.remove = True\n \n     def __enter__(self):\n-        files = glob.glob(self.pattern)\n-        if files and not files[0].endswith(self.end):\n-            # Keep the string \"LOCKERROR\" in this string so that external\n-            # programs can look for it.\n-            raise RuntimeError(\"\"\"\\\n-LOCKERROR: It looks like conda is already doing something.\n-The lock %s was found. Wait for it to finish before continuing.\n-If you are sure that conda is not running, remove it and try again.\n-You can also use: $ conda clean --lock\"\"\" % self.lock_path)\n+        retries = 10\n+        # Keep the string \"LOCKERROR\" in this string so that external\n+        # programs can look for it.\n+        lockstr = (\"\"\"\\\n+    LOCKERROR: It looks like conda is already doing something.\n+    The lock %s was found. Wait for it to finish before continuing.\n+    If you are sure that conda is not running, remove it and try again.\n+    You can also use: $ conda clean --lock\"\"\" % self.lock_path)\n+        sleeptime = 1\n+        while retries:\n+            files = glob.glob(self.pattern)\n+            if files and not files[0].endswith(self.end):\n+                print(lockstr)\n+                print(\"Sleeping for %s seconds\" % sleeptime)\n+                sleep(sleeptime)\n+                sleeptime *= 2\n+                retries -= 1\n+            else:\n+                break\n+        else:\n+            print(\"Exceeded max retries, giving up\")\n+            raise RuntimeError(lockstr)\n \n         if not files:\n             try:\n", "issue": "Add ability to keep retrying with a lock error\nThe yum installer (IIRC) has a nice feature that it will keep trying every 10 seconds or so if there is a lock error. This could be useful for conda. \n\n", "before_files": [{"content": "# (c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io\n# All Rights Reserved\n#\n# conda is distributed under the terms of the BSD 3-clause license.\n# Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.\n\n\"\"\"\nTools for working with locks\n\nA lock is just an empty directory. We use directories because this lets us use\nthe race condition-proof os.makedirs.\n\nFor now, there is one global lock for all of conda, because some things happen\nglobally (such as downloading packages).\n\nWe don't raise an error if the lock is named with the current PID\n\"\"\"\n\nimport os\nfrom os.path import join\nimport glob\n\n\nLOCKFN = '.conda_lock'\n\n\nclass Locked(object):\n    \"\"\"\n    Context manager to handle locks.\n    \"\"\"\n    def __init__(self, path):\n        self.path = path\n        self.end = \"-\" + str(os.getpid())\n        self.lock_path = join(self.path, LOCKFN + self.end)\n        self.pattern = join(self.path, LOCKFN + '-*')\n        self.remove = True\n\n    def __enter__(self):\n        files = glob.glob(self.pattern)\n        if files and not files[0].endswith(self.end):\n            # Keep the string \"LOCKERROR\" in this string so that external\n            # programs can look for it.\n            raise RuntimeError(\"\"\"\\\nLOCKERROR: It looks like conda is already doing something.\nThe lock %s was found. Wait for it to finish before continuing.\nIf you are sure that conda is not running, remove it and try again.\nYou can also use: $ conda clean --lock\"\"\" % self.lock_path)\n\n        if not files:\n            try:\n                os.makedirs(self.lock_path)\n            except OSError:\n                pass\n        else: # PID lock already here --- someone else will remove it.\n            self.remove = False\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        if self.remove:\n            for path in self.lock_path, self.path:\n                try:\n                    os.rmdir(path)\n                except OSError:\n                    pass\n", "path": "conda/lock.py"}]}