fix stupid and dangerous bugs with sleeps not working
This commit is contained in:
parent
0b198cc5c0
commit
a71d9c33d7
1 changed files with 18 additions and 9 deletions
|
@ -193,17 +193,17 @@ async def try_all_ips(db, try_me, checks, opts: Options, callback=None):
|
|||
from asyncio import create_task, sleep, BoundedSemaphore
|
||||
|
||||
seen, total = 0, None
|
||||
sem = BoundedSemaphore(opts.ip_simul)
|
||||
|
||||
async def process(ip):
|
||||
async def _process(ip):
|
||||
nonlocal seen
|
||||
first = seen == 0
|
||||
seen += 1
|
||||
if opts.progress:
|
||||
lament(f"#{seen}: {ip}" if total is None else f"#{seen}/{total}: {ip}")
|
||||
stderr.flush()
|
||||
if not first:
|
||||
await sleep(opts.ip_wait)
|
||||
|
||||
first_failure = await try_ip(db, ip, checks, opts, callback)
|
||||
|
||||
if first_failure is None:
|
||||
print(ip) # all tests for this server passed; pass it along to stdout
|
||||
elif opts.dry: # don't save the error anywhere; pass it along to stdout
|
||||
|
@ -214,14 +214,23 @@ async def try_all_ips(db, try_me, checks, opts: Options, callback=None):
|
|||
else:
|
||||
print(ip, ff.reason, ff.kind, ff.domain, sep="\t")
|
||||
|
||||
sem = BoundedSemaphore(opts.ip_simul)
|
||||
async def process(ip):
|
||||
try:
|
||||
await _process(ip)
|
||||
finally:
|
||||
sem.release()
|
||||
|
||||
tasks = []
|
||||
while (res := await try_me.get()) is not None:
|
||||
ip, total = res
|
||||
#lament("TRYING", ip)
|
||||
async with sem:
|
||||
task = create_task(process(ip))
|
||||
tasks.append(task)
|
||||
if len(tasks) > 0:
|
||||
await sleep(opts.ip_wait)
|
||||
ip, total = res
|
||||
# acquire now instead of within the task so
|
||||
# a ton of tasks aren't created all at once.
|
||||
await sem.acquire()
|
||||
task = create_task(process(ip))
|
||||
tasks.append(task)
|
||||
for task in tasks:
|
||||
await task
|
||||
|
||||
|
|
Loading…
Reference in a new issue