Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot authored Oct 20, 2023
2 parents ba424b4 + 9279047 commit cfe2c7a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions redbot/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@
notify = Notification = None # pylint: disable=invalid-name

_loop.precision = 0.2
_loop.debug = True


def print_debug(message: str, profile: Optional[cProfile.Profile]) -> None:
sys.stderr.write(f"WARNING: {message}\n\n")
if profile:
st = io.StringIO()
ps = Stats(profile, stream=st).sort_stats("cumulative")
ps.print_stats(15)
sys.stderr.write(f"{st.getvalue()}\n")


_loop.debug_out = print_debug # type: ignore

# dump stack on faults
faulthandler.enable()
Expand Down Expand Up @@ -230,8 +217,27 @@ def not_found(self, path: bytes) -> None:
self.exchange.response_done([])


def print_debug(message: str, profile: Optional[cProfile.Profile]) -> None:
sys.stderr.write(f"WARNING: {message}\n\n")
if profile:
st = io.StringIO()
ps = Stats(profile, stream=st).sort_stats("cumulative")
ps.print_stats(15)
sys.stderr.write(f"{st.getvalue()}\n")


_loop.debug_out = print_debug # type: ignore


def main() -> None:
parser = argparse.ArgumentParser(description="REDbot daemon")
parser.add_argument(
"-d",
"--debug",
action="store_true",
dest="debug",
help="Dump slow operations to STDERR",
)
parser.add_argument(
"config_file", type=argparse.FileType("r"), help="configuration file"
)
Expand All @@ -245,6 +251,9 @@ def main() -> None:
print("Warning: Failed to set locale from config. Using default 'en' locale.")
locale.setlocale(locale.LC_ALL, "en_US.UTF-8") # Default to English locale

if args.debug:
_loop.debug = True

sys.stderr.write(
f"Starting on PID {os.getpid()}... (thor {thor.__version__})\n"
+ f"http://{conf['redbot'].get('host', '')}:{conf['redbot']['port']}/\n"
Expand Down

0 comments on commit cfe2c7a

Please sign in to comment.