prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  CTFd crash right after install
  ## Git + python 3.7.2 (3b1b82b9a0fbcb8731d7a3a3bbac99499c466c99)
  
  [![asciicast](https://asciinema.org/a/iHDMVNRWSYJDTZUgIy4wIBsOK.svg)](https://asciinema.org/a/iHDMVNRWSYJDTZUgIy4wIBsOK)
  
  ## Git + python 2.7.15 (3b1b82b9a0fbcb8731d7a3a3bbac99499c466c99)
  
  [![asciicast](https://asciinema.org/a/JRqfe0rMl0QeZAEklyvV1LQX9.svg)](https://asciinema.org/a/JRqfe0rMl0QeZAEklyvV1LQX9)
  
  ## 2.1.4 + python 3.7.2
  
  [![asciicast](https://asciinema.org/a/wErebw8ZN2HFER9P71tLW4FBv.svg)](https://asciinema.org/a/wErebw8ZN2HFER9P71tLW4FBv)
  
  **Environment**:
  
    - CTFd Version/Commit: see titles
    - Operating System: ArchLinux
    - Web Browser and Version: Firefox
  
  **What happened?**
  
  CTFd crash right after install.
  
  **What did you expect to happen?**
  
  Working or at least a more comprehensible error.
  
  **How to reproduce your issue**
  
  See the asciinema, but basically
  
  - Download CTFd
  - Install dependencies
  - run flask
  - crash
  
  PS : with the untouched default config
  
  **Any associated stack traces or error logs**
  
  See the asciinema
  
  </issue>
  <code>
  [start of wsgi.py]
  1 from gevent import monkey
  2 monkey.patch_all()
  3 from CTFd import create_app
  4 
  5 app = create_app()
  6 
  7 if __name__ == '__main__':
  8     app.run(debug=True, threaded=True, host="127.0.0.1", port=4000)
  9
  [end of wsgi.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/wsgi.py b/wsgi.py
  --- a/wsgi.py
  +++ b/wsgi.py
  @@ -1,8 +1,14 @@
  -from gevent import monkey
  -monkey.patch_all()
  +import os
  +
  +# Detect if we're running via `flask run` and don't monkey patch
  +if not os.getenv("FLASK_RUN_FROM_CLI"):
  +    from gevent import monkey
  +
  +    monkey.patch_all()
  +
   from CTFd import create_app
   
   app = create_app()
   
  -if __name__ == '__main__':
  +if __name__ == "__main__":
       app.run(debug=True, threaded=True, host="127.0.0.1", port=4000)
  
verification_info: {"golden_diff": "diff --git a/wsgi.py b/wsgi.py\n--- a/wsgi.py\n+++ b/wsgi.py\n@@ -1,8 +1,14 @@\n-from gevent import monkey\n-monkey.patch_all()\n+import os\n+\n+# Detect if we're running via `flask run` and don't monkey patch\n+if not os.getenv(\"FLASK_RUN_FROM_CLI\"):\n+    from gevent import monkey\n+\n+    monkey.patch_all()\n+\n from CTFd import create_app\n \n app = create_app()\n \n-if __name__ == '__main__':\n+if __name__ == \"__main__\":\n     app.run(debug=True, threaded=True, host=\"127.0.0.1\", port=4000)\n", "issue": "CTFd crash right after install\n## Git + python 3.7.2 (3b1b82b9a0fbcb8731d7a3a3bbac99499c466c99)\r\n\r\n[![asciicast](https://asciinema.org/a/iHDMVNRWSYJDTZUgIy4wIBsOK.svg)](https://asciinema.org/a/iHDMVNRWSYJDTZUgIy4wIBsOK)\r\n\r\n## Git + python 2.7.15 (3b1b82b9a0fbcb8731d7a3a3bbac99499c466c99)\r\n\r\n[![asciicast](https://asciinema.org/a/JRqfe0rMl0QeZAEklyvV1LQX9.svg)](https://asciinema.org/a/JRqfe0rMl0QeZAEklyvV1LQX9)\r\n\r\n## 2.1.4 + python 3.7.2\r\n\r\n[![asciicast](https://asciinema.org/a/wErebw8ZN2HFER9P71tLW4FBv.svg)](https://asciinema.org/a/wErebw8ZN2HFER9P71tLW4FBv)\r\n\r\n**Environment**:\r\n\r\n  - CTFd Version/Commit: see titles\r\n  - Operating System: ArchLinux\r\n  - Web Browser and Version: Firefox\r\n\r\n**What happened?**\r\n\r\nCTFd crash right after install.\r\n\r\n**What did you expect to happen?**\r\n\r\nWorking or at least a more comprehensible error.\r\n\r\n**How to reproduce your issue**\r\n\r\nSee the asciinema, but basically\r\n\r\n- Download CTFd\r\n- Install dependencies\r\n- run flask\r\n- crash\r\n\r\nPS : with the untouched default config\r\n\r\n**Any associated stack traces or error logs**\r\n\r\nSee the asciinema\n", "before_files": [{"content": "from gevent import monkey\nmonkey.patch_all()\nfrom CTFd import create_app\n\napp = create_app()\n\nif __name__ == '__main__':\n    app.run(debug=True, threaded=True, host=\"127.0.0.1\", port=4000)\n", "path": "wsgi.py"}]}