Last active
April 17, 2020 10:57
-
-
Save cool-RR/8f5715cda9b64e0bff443a8c1109af51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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