spawn_tor: catch OSError and wrap as ClanError
This commit is contained in:
@@ -43,18 +43,22 @@ def spawn_tor() -> Iterator[None]:
|
|||||||
cmd_args = ["tor", "--HardwareAccel", "1"]
|
cmd_args = ["tor", "--HardwareAccel", "1"]
|
||||||
packages = ["tor"]
|
packages = ["tor"]
|
||||||
cmd = nix_shell(packages, cmd_args)
|
cmd = nix_shell(packages, cmd_args)
|
||||||
process = Popen(cmd)
|
|
||||||
try:
|
try:
|
||||||
while not is_tor_running():
|
process = Popen(cmd)
|
||||||
log.debug("Waiting for Tor to start...")
|
try:
|
||||||
time.sleep(0.2)
|
while not is_tor_running():
|
||||||
log.info("Tor is now running")
|
log.debug("Waiting for Tor to start...")
|
||||||
yield
|
time.sleep(0.2)
|
||||||
finally:
|
log.info("Tor is now running")
|
||||||
log.info("Terminating Tor process...")
|
yield
|
||||||
process.terminate()
|
finally:
|
||||||
process.wait()
|
log.info("Terminating Tor process...")
|
||||||
log.info("Tor process terminated")
|
process.terminate()
|
||||||
|
process.wait()
|
||||||
|
log.info("Tor process terminated")
|
||||||
|
except OSError as e:
|
||||||
|
msg = f"Failed to spawn tor process with command: {cmd}"
|
||||||
|
raise ClanError(msg) from e
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user