Skip to content

Commit

Permalink
Update CF-Handler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkkl authored Nov 10, 2024
1 parent 504b749 commit 3a239bf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions CF-Handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import threading
import sys

def send_stats_command(process):
"""Periodically sends /stats command to the process"""
def autostats(process):
while process.poll() is None:
try:
process.stdin.write(b"/stats\n")
process.stdin.flush()
except:
break
time.sleep(1200)
time.sleep(3600)

def handle_user_input(process):
def user_input(process):
"""Handles user input and sends it to the process"""
while process.poll() is None:
try:
Expand All @@ -37,26 +36,26 @@ def run_and_monitor():
universal_newlines=False
)
stats_thread = threading.Thread(
target=send_stats_command,
target=autostats,
args=(process,),
daemon=True
)
stats_thread.start()
input_thread = threading.Thread(
target=handle_user_input,
target=user_input,
args=(process,),
daemon=True
)
input_thread.start()
def print_output():
def output():
while process.poll() is None:
line = process.stdout.readline()
if line:
sys.stdout.buffer.write(line)
sys.stdout.buffer.flush()

output_thread = threading.Thread(
target=print_output,
target=output,
daemon=True
)
output_thread.start()
Expand Down

0 comments on commit 3a239bf

Please sign in to comment.