Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
per4m/per4m/example1.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (30 sloc)
774 Bytes
This file contains 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
# same as example1, but without explicit viztracer calls | |
import threading | |
import time | |
# if we don't run with gil_load, we just skip it | |
import gil_load | |
try: | |
gil_load.init() | |
gil_load.start() | |
use_gil_load = True | |
except RuntimeError: | |
use_gil_load = False | |
def some_computation(): | |
total = 0 | |
for i in range(1_000_000): | |
total += i | |
return total | |
thread1 = threading.Thread(target=some_computation) | |
thread2 = threading.Thread(target=some_computation) | |
def main(args=None): | |
thread1.start() | |
thread2.start() | |
time.sleep(0.2) | |
for thread in [thread1, thread2]: | |
thread.join() | |
if use_gil_load: | |
gil_load.stop() | |
stats = gil_load.get() | |
print(gil_load.format(stats)) | |
if __name__ == "__main__": | |
main() |