Skip to content

Instantly share code, notes, and snippets.

@zurk
Created September 15, 2017 13:04
Show Gist options
  • Save zurk/07ca43333c02ea15cee53a361f0c6394 to your computer and use it in GitHub Desktop.
Save zurk/07ca43333c02ea15cee53a361f0c6394 to your computer and use it in GitHub Desktop.
import threading
import time
import logging
from bblfsh import BblfshClient
BBLFSH_ENDPOINT = "172.17.0.1:9437"
#BBLFSH_ENDPOINT = "0.0.0.0:9432"
LANG = "Python"
NUM_THREADS = 32
STOP_TIME = 1200
TIMEOUT = 30
bblfsh = [BblfshClient(BBLFSH_ENDPOINT) for _ in range(NUM_THREADS)]
stop = False
with open("python_files.txt") as f:
python_files = f.readlines()
def thread_loop(thread_idx, filenames):
log = logging.getLogger('hang_test')
log.setLevel(logging.INFO)
for filename in filenames:
log.warning("%d thread. Parse %s", thread_idx, filename[:-1])
try:
res = bblfsh[thread_idx].parse(filename[:-1], language=LANG, timeout=TIMEOUT)
except Exception as e:
log.exception("%d thread. Parse %s", thread_idx, filename)
start_time = time.time()
pool = [threading.Thread(target=thread_loop, args=(i, python_files[i::NUM_THREADS]),
name=str(i))
for i in range(NUM_THREADS)]
for thread in pool:
thread.start()
time.sleep(STOP_TIME)
stop = True
for thread in pool:
thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment