Use datetimes

This commit is contained in:
Rémi Oudin 2018-02-26 09:49:24 +01:00
parent 71d9e18eec
commit 8f5c4f3f0f
1 changed files with 10 additions and 8 deletions

View File

@ -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):