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
import pty, sys, os, re, tty, select | |
class ReadBuffer(object): | |
"""Buffer read operations""" | |
def __init__(self, fd): | |
if isinstance(fd, file): | |
fd = fd.fileno() | |
self.fd = fd |
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
from bisect import * | |
##### HELPER FUNCTIONS FROM PYTHON DOCUMENTATION ##### | |
def index(a, x): | |
'Locate the leftmost value exactly equal to x' | |
i = bisect_left(a, x) | |
if i != len(a) and a[i] == x: | |
return i | |
raise ValueError |
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
from collections import deque | |
class SearchQueue(object): | |
"""BFS search queue""" | |
def __init__(self, seeds=[]): | |
"""Initialize with an optional list of seeds""" | |
self.Q = deque() | |
self.explored = set() | |
self.pushAll(seeds) |
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
import sys,subprocess,time | |
class ProgressBar: | |
"""Class to handle a progress bar for a given job size""" | |
def __init__(self, jobSize, leader='', logger=sys.stdout, maxCols=80): | |
ttyr,ttyc = self.ttysize() | |
self.nCols = min(ttyc,maxCols-2) - len(leader) | |
self.n = jobSize | |
self.counter = 0 |
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
from multiprocessing import Process, BoundedSemaphore, RawArray, Pipe, cpu_count, RawValue | |
from threading import Thread | |
import resource, time, sys, os, signal | |
try: | |
import psutil | |
except: | |
print("psutil import failure -- ParallelJob timeouts disabled") | |
################################################################################ |