Add custom message when the user exits an app (#1345)
This commit is contained in:
parent
7397cd795a
commit
d6b191538e
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import signal
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -163,6 +164,9 @@ def run(
|
|||||||
args=(app.__name__, backend_host, backend_port, loglevel),
|
args=(app.__name__, backend_host, backend_port, loglevel),
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
|
# Display custom message when there is a keyboard interrupt.
|
||||||
|
signal.signal(signal.SIGINT, processes.catch_keyboard_interrupt)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def deploy(dry_run: bool = typer.Option(False, help="Whether to run a dry run.")):
|
def deploy(dry_run: bool = typer.Option(False, help="Whether to run a dry run.")):
|
||||||
|
@ -7,6 +7,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@ -145,3 +146,14 @@ def new_process(args, **kwargs):
|
|||||||
args,
|
args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def catch_keyboard_interrupt(signal, frame):
|
||||||
|
"""Display a custom message with the current time when exiting an app.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
signal: The keyboard interrupt signal.
|
||||||
|
frame: The current stack frame.
|
||||||
|
"""
|
||||||
|
current_time = datetime.now().isoformat()
|
||||||
|
console.print(f"\nReflex app stopped at time: {current_time}")
|
||||||
|
Loading…
Reference in New Issue
Block a user