Skip to content

Commit

Permalink
don't track context manager status for BackgroundHTTPServer
Browse files Browse the repository at this point in the history
There is actually no possible case where __exit__ would be called
without __enter__, even if the server is used in an existing
context manager block.

The only case to ever legitimately call __exit__ is if the instance
was created by a context manager in the first place, and __enter__
was called.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
  • Loading branch information
comps committed Jul 15, 2024
1 parent 0372edd commit 5ba9d73
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/util/httpsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def log_message(self, form, *args):
class BackgroundHTTPServer:
def __init__(self, host, port):
self.server = None
self.created_by_context = False
self.file_mapping = {}
self.dir_mapping = {}
self.requested_address = (host, port)
Expand Down Expand Up @@ -192,9 +191,7 @@ def stop(self):
stdout=subprocess.DEVNULL, check=True)

def __enter__(self):
self.created_by_context = True
return self

def __exit__(self, exc_type, exc_value, traceback):
if self.created_by_context:
self.stop()
self.stop()

0 comments on commit 5ba9d73

Please sign in to comment.