Skip to content

Instantly share code, notes, and snippets.

@cool-RR
Last active April 17, 2020 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cool-RR/8f5715cda9b64e0bff443a8c1109af51 to your computer and use it in GitHub Desktop.
Save cool-RR/8f5715cda9b64e0bff443a8c1109af51 to your computer and use it in GitHub Desktop.
import time as time_module
import pprint
import collections
import traceback as traceback_module
import itertools
import threading
import sys
import inspect
def generator():
for i in itertools.count():
yield i
def get_stacktraces():
return [''.join(traceback_module.format_stack(frame)) for frame in
sys._current_frames().values()]
class ActionThread(threading.Thread):
_exit = False
def exit(self):
self._exit = True
self.join()
def run(self):
for _ in generator():
if self._exit:
return
class InspectionThread(threading.Thread):
def run(self):
stacktrace_counter = collections.Counter()
for _ in range(100):
for stacktrace in get_stacktraces():
if stacktrace not in stacktrace_counter:
print(stacktrace)
stacktrace_counter[stacktrace] += 1
# time_module.sleep(0)
pprint.pprint(tuple(stacktrace_counter.values()))
inspection_thread = InspectionThread()
inspection_thread.start()
action_thread = ActionThread()
action_thread.start()
inspection_thread.join()
action_thread.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment