Skip to content

Commit

Permalink
Add Ctrl+C sigal handler for --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-menon committed Aug 3, 2024
1 parent dd45fa4 commit 80ff04e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion alteza/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import shutil
import signal
import sys
import time
import types
Expand Down Expand Up @@ -331,6 +332,8 @@ class Engine:
# This class should never be instantiated, and most functions not called directly.
# Engine.generate(...) is called to write the output of a processed Content object.
# Similarly, Engine.run(args) is used to invoke Alteza overall.
shouldExit: bool = False

@staticmethod
def generateMdContents(md: Md) -> None:
if os.path.exists("index.html"):
Expand Down Expand Up @@ -475,7 +478,15 @@ def watching() -> None:
observer.start()
try:
watching()
while True:

def signalHandler(sig: int, frame: Optional[types.FrameType]) -> None:
# pylint: disable=unused-argument
print("\nExiting...")
Engine.shouldExit = True

signal.signal(signal.SIGINT, signalHandler)

while not Engine.shouldExit:
time.sleep(timeIntervalSecs)
if eventHandler.timeOfMostRecentEvent:
timeSinceMostRecentEvent = time.time_ns() - (
Expand Down

0 comments on commit 80ff04e

Please sign in to comment.