def thread(thread_count): """validate threads""" try: int(thread_count) except: raise ValueError(thread_count + "is not an integer") if int(thread_count) > settings.threads(): raise ValueError("you have exceeded the thread limitation")
def batch(self, date): """multiprocessing to get all the events""" batched = [] mpool = multiprocessing.Pool(settings.threads(), self.utility.init_worker) paginations = list(range(1, settings.pagination_limit() + 1)) per_page = str(settings.per_page()) try: partial_get = partial(self.get, per_page, date) data = mpool.map(partial_get, paginations) for i in data: batched.extend(i["events"]) return batched except KeyboardInterrupt: print "Caught KeyboardInterrupt, terminating workers" mpool.terminate() mpool.join()
def parse_threads(self): """determine threads""" if self.options['threads'] is None: return settings.threads() validate.thread(self.options["threads"]) return self.options['threads']