summaryrefslogtreecommitdiffstats
path: root/deluge/ui/web/server.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2016-10-11 11:26:52 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2016-10-18 18:40:25 +0100
commit9dd3b1617d44d717fc8d2844d40bd61969c1a157 (patch)
treead4d29f211bf4cc5d4642ba50128c48efa6459f3 /deluge/ui/web/server.py
parent58835eeb2ea974962527d9848b18c6560b7ff881 (diff)
downloaddeluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.tar.gz
deluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.tar.bz2
deluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.zip
[#2889] Fixes for 'Too many files open' error
* Ensure all file descriptors are closed. Using the with statement ensures closure. * The main problem was with thousands of unclosed file desciptors from tracker_icons mkstemp. * Use a prefix 'deluge_ticon.' to identify created tracker_icon tmp files.
Diffstat (limited to 'deluge/ui/web/server.py')
-rw-r--r--deluge/ui/web/server.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py
index f0b6131d3..fa4aa2438 100644
--- a/deluge/ui/web/server.py
+++ b/deluge/ui/web/server.py
@@ -183,9 +183,10 @@ class Flag(resource.Resource):
request.setHeader("cache-control",
"public, must-revalidate, max-age=86400")
request.setHeader("content-type", "image/png")
- data = open(filename, "rb")
+ with open(filename, "rb") as _file:
+ data = _file.read()
request.setResponseCode(http.OK)
- return data.read()
+ return data
else:
request.setResponseCode(http.NOT_FOUND)
return ""
@@ -232,7 +233,9 @@ class LookupResource(resource.Resource, component.Component):
log.debug("Serving path: '%s'", path)
mime_type = mimetypes.guess_type(path)
request.setHeader("content-type", mime_type[0])
- return compress(open(path, "rb").read(), request)
+ with open(path, "rb") as _file:
+ data = _file.read()
+ return compress(data, request)
request.setResponseCode(http.NOT_FOUND)
return "<h1>404 - Not Found</h1>"
@@ -390,7 +393,9 @@ class ScriptResource(resource.Resource, component.Component):
log.debug("Serving path: '%s'", path)
mime_type = mimetypes.guess_type(path)
request.setHeader("content-type", mime_type[0])
- return compress(open(path, "rb").read(), request)
+ with open(path, "rb") as _file:
+ data = _file.read()
+ return compress(data, request)
request.setResponseCode(http.NOT_FOUND)
return "<h1>404 - Not Found</h1>"