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
|
from asyncio import create_task, sleep, BoundedSemaphore
|
||||||
|
|
||||||
seen, total = 0, None
|
seen, total = 0, None
|
||||||
|
sem = BoundedSemaphore(opts.ip_simul)
|
||||||
|
|
||||||
async def process(ip):
|
async def _process(ip):
|
||||||
nonlocal seen
|
nonlocal seen
|
||||||
first = seen == 0
|
|
||||||
seen += 1
|
seen += 1
|
||||||
if opts.progress:
|
if opts.progress:
|
||||||
lament(f"#{seen}: {ip}" if total is None else f"#{seen}/{total}: {ip}")
|
lament(f"#{seen}: {ip}" if total is None else f"#{seen}/{total}: {ip}")
|
||||||
stderr.flush()
|
stderr.flush()
|
||||||
if not first:
|
|
||||||
await sleep(opts.ip_wait)
|
|
||||||
first_failure = await try_ip(db, ip, checks, opts, callback)
|
first_failure = await try_ip(db, ip, checks, opts, callback)
|
||||||
|
|
||||||
if first_failure is None:
|
if first_failure is None:
|
||||||
print(ip) # all tests for this server passed; pass it along to stdout
|
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
|
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:
|
else:
|
||||||
print(ip, ff.reason, ff.kind, ff.domain, sep="\t")
|
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 = []
|
tasks = []
|
||||||
while (res := await try_me.get()) is not None:
|
while (res := await try_me.get()) is not None:
|
||||||
ip, total = res
|
|
||||||
#lament("TRYING", ip)
|
#lament("TRYING", ip)
|
||||||
async with sem:
|
if len(tasks) > 0:
|
||||||
task = create_task(process(ip))
|
await sleep(opts.ip_wait)
|
||||||
tasks.append(task)
|
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:
|
for task in tasks:
|
||||||
await task
|
await task
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue