Skip to content

Commit

Permalink
Added context manager to Server class
Browse files Browse the repository at this point in the history
  • Loading branch information
RudreshVeerkhare committed Nov 2, 2022
1 parent d2efa16 commit 7dc4379
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gcp_storage_emulator/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ def __init__(self, host, port, in_memory, default_bucket=None, data_dir=None):
buckets.create_bucket(default_bucket, self._storage)
self._api = APIThread(host, port, self._storage)

# Context Manager
def __enter__(self):
self.start()
return self

def __exit__(self, *args):
self.stop()

def start(self):
self._api.start()
self._api.is_running.wait() # Start the API thread
Expand Down

0 comments on commit 7dc4379

Please sign in to comment.