Skip to content

Commit

Permalink
Use None instead of del (#2747)
Browse files Browse the repository at this point in the history
* Use None instead of del

* Other review

* rm test iter()
  • Loading branch information
RunDevelopment authored Apr 5, 2024
1 parent 92717c2 commit bc331c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions backend/src/server_process_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,27 @@ def __init__(self, flags: list[str]):
self._stop_event = threading.Event()

# Create a separate thread to read and print the output of the subprocess
self.t1 = threading.Thread(
self._reader_thread = threading.Thread(
target=self._read_output,
daemon=True,
name="output reader",
)
self.t1.daemon = True
self.t1.start()
self._reader_thread.daemon = True
self._reader_thread.start()

def close(self):
logger.info("Closing worker process...")
self._stop_event.set()
if hasattr(self, "_process"):
if self._process is not None:
self._process.terminate()
self._process.kill()
del self._process
if hasattr(self, "t1"):
del self.t1
self._process = None
self._reader_thread = None

def _read_output(self):
if self._process.stdout is None:
if self._process is None or self._process.stdout is None:
return
for line in iter(self._process.stdout):
for line in self._process.stdout:
if self._stop_event.is_set():
break
stripped_line = line.rstrip()
Expand Down
2 changes: 1 addition & 1 deletion src/main/backend/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class OwnedBackendProcess implements BaseBackendProcess {
return;
}

await fetch(`${this.url}/shutdown`, { method: 'POST' });
await getBackend(this.url).shutdown();
if (this.process.kill()) {
this.process = undefined;
log.info('Successfully killed backend.');
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const registerEventHandlerPostSetup = (
if (backend.owned) {
backend
.tryKill()
.then(() => {
.finally(() => {
app.relaunch();
app.exit();
})
Expand Down

0 comments on commit bc331c1

Please sign in to comment.