diff --git a/histories/tor_runner.py b/histories/tor_runner.py index 08e6620..5b9b878 100644 --- a/histories/tor_runner.py +++ b/histories/tor_runner.py @@ -3,10 +3,11 @@ Modules that handles tor instaces creations in order to safely run histories """ import shutil +import datetime as dt +from time import sleep import asyncio import aiohttp from aiosocks.connector import ProxyConnector, ProxyClientRequest -from time import sleep import async_timeout import stem.process as tor @@ -57,15 +58,16 @@ class TorInstance(): async def run(self): """ Runs the Tor Instance on the history. """ - t_start = time.now() - while history: - item = history.pop(0) + while (self.history[0][1] - dt.datetime.now()).total_seconds >= 10: + print("Sleeping") + sleep(10) + while self.history: + item = self.history.pop(0) async with async_timeout.timeout(30): await(self.query(item[0])) - t_end = time.now() - diff = (history[0][1] - item[0]) - (t_end - t_start) - if diff > 0: - sleep(diff) + now = dt.datetime.now() + if now <= self.history[0][1]: + sleep((self.history[0][1] - now).total_seconds()) def create_session(self):