From 8f5c4f3f0fdfdae39be283e1ff3e24e9f1c8f809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Mon, 26 Feb 2018 09:49:24 +0100 Subject: [PATCH] Use datetimes --- histories/tor_runner.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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):