Skip to content

Instantly share code, notes, and snippets.

@meaksh
Last active August 7, 2019 15:52
Show Gist options
  • Select an option

  • Save meaksh/0c603a62b7189f051aa31bfba2bb8171 to your computer and use it in GitHub Desktop.

Select an option

Save meaksh/0c603a62b7189f051aa31bfba2bb8171 to your computer and use it in GitHub Desktop.

Revisions

  1. meaksh renamed this gist Aug 7, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. meaksh created this gist Aug 7, 2019.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import tracemalloc
    import threading
    from salt.scripts import salt_master

    import signal
    import sys

    stop_flag = False

    def print_stats():
    snapshot = tracemalloc.take_snapshot()
    top_stats = snapshot.statistics('lineno')
    print("[ Top 50 ]")
    for stat in top_stats[:50]:
    print(stat)

    def signal_handler(sig, frame):
    global stop_flag
    stop_flag = True
    print_stats()
    print('You pressed Ctrl+C!')
    sys.exit(0)

    def timer_stats():
    global stop_flag
    print_stats()
    if not stop_flag:
    t = threading.Timer(5.0, timer_stats)
    t.daemon = True
    t.start()

    signal.signal(signal.SIGINT, signal_handler)
    tracemalloc.start(25)
    timer_stats()
    salt_master()