mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 15:05:59 +08:00
hard exit when memory is more than 300MB
This commit is contained in:
parent
7a3a6784cc
commit
e988573cb4
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import gnupg
|
||||
|
@ -24,11 +25,22 @@ def load_public_key(public_key: str) -> str:
|
|||
raise PGPException("Cannot load key") from e
|
||||
|
||||
|
||||
def hard_exit():
|
||||
pid = os.getpid()
|
||||
LOG.warning("kill pid %s", pid)
|
||||
os.kill(pid, 9)
|
||||
|
||||
|
||||
def encrypt_file(data: BytesIO, fingerprint: str) -> str:
|
||||
LOG.d("encrypt for %s", fingerprint)
|
||||
mem_usage = memory_usage(-1, interval=1, timeout=1)
|
||||
mem_usage = memory_usage(-1, interval=1, timeout=1)[0]
|
||||
LOG.d("mem_usage %s", mem_usage)
|
||||
|
||||
# todo
|
||||
if mem_usage > 300:
|
||||
LOG.error("Force exit")
|
||||
hard_exit()
|
||||
|
||||
r = gpg.encrypt_file(data, fingerprint, always_trust=True)
|
||||
if not r.ok:
|
||||
LOG.error("Try encrypt again %s", fingerprint)
|
||||
|
|
Loading…
Reference in a new issue