MCPcopy
hub / github.com/mikf/gallery-dl / wait

Method wait

gallery_dl/extractor/common.py:312–344  ·  view source on GitHub ↗
(self, seconds=None, until=None, adjust=1.0,
             reason="rate limit")

Source from the content-addressed store, hash-verified

310 _handle_429 = util.false
311
312 def wait(self, seconds=None, until=None, adjust=1.0,
313 reason="rate limit"):
314 now = time.time()
315
316 if seconds:
317 seconds = float(seconds)
318 until = now + seconds
319 elif until:
320 if isinstance(until, dt.datetime):
321 # convert to UTC timestamp
322 until = dt.to_ts(until)
323 else:
324 until = float(until)
325 seconds = until - now
326 else:
327 raise ValueError("Either 'seconds' or 'until' is required")
328
329 seconds += adjust
330 if seconds <= 0.0:
331 return
332
333 if reason:
334 if seconds >= 3600.0:
335 h, m = divmod(seconds, 3600.0)
336 dur = f"{int(h)}h {int(m/60.0)}min"
337 elif seconds >= 60.0:
338 dur = str(int(seconds/60.0)) + " minutes"
339 else:
340 dur = str(int(seconds)) + " seconds"
341 t = time.localtime(until)
342 iso = f"{t.tm_hour:02}:{t.tm_min:02}:{t.tm_sec:02}"
343 self.log.info("Waiting for %s until %s (%s)", dur, iso, reason)
344 time.sleep(seconds)
345
346 def sleep(self, seconds, reason):
347 self.log.debug("Sleeping %.2f seconds (%s)",

Callers 15

requestMethod · 0.95
test_wait_secondsMethod · 0.80
test_wait_untilMethod · 0.80
open_externFunction · 0.80
Popen_communicateFunction · 0.80
_execFunction · 0.80
_execMethod · 0.80
_execMethod · 0.80
_callMethod · 0.80
_callMethod · 0.80

Calls 2

sleepMethod · 0.80
infoMethod · 0.45

Tested by 4

test_wait_secondsMethod · 0.64
test_wait_untilMethod · 0.64