-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown.py
More file actions
28 lines (24 loc) · 722 Bytes
/
shutdown.py
File metadata and controls
28 lines (24 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import threading
import os
from typing import Optional
def start_enter_watcher(conversation_obj: Optional[object]) -> threading.Thread:
"""Start a background daemon thread that waits for Enter and then ends the conversation and exits.
Returns the Thread object.
"""
def _wait():
try:
input("Press Enter to terminate the session\n")
except Exception:
pass
try:
if conversation_obj is not None:
conversation_obj.end_session()
except Exception:
pass
try:
os._exit(0)
except Exception:
pass
t = threading.Thread(target=_wait, daemon=True)
t.start()
return t