MCPcopy
hub / github.com/apenwarr/redo / _ensure_token

Function _ensure_token

redo/jobserver.py:348–383  ·  view source on GitHub ↗

Don't return until this process has a job token. Args: reason: the reason (for debugging purposes) we need a token. Usually the name of a target we want to build. max_delay: the max time to wait for a token, or None if forever. Returns: None, but has_token() is no

(reason, max_delay=None)

Source from the content-addressed store, hash-verified

346
347
348def _ensure_token(reason, max_delay=None):
349 """Don't return until this process has a job token.
350
351 Args:
352 reason: the reason (for debugging purposes) we need a token. Usually
353 the name of a target we want to build.
354 max_delay: the max time to wait for a token, or None if forever.
355 Returns:
356 None, but has_token() is now true *unless* max_delay is non-None
357 and we timed out.
358 """
359 global _mytokens
360 assert state.is_flushed()
361 assert _mytokens <= 1
362 while 1:
363 if _mytokens >= 1:
364 _debug("_mytokens is %d\n" % _mytokens)
365 assert _mytokens == 1
366 _debug('(%r) used my own token...\n' % reason)
367 break
368 assert _mytokens < 1
369 _debug('(%r) waiting for tokens...\n' % reason)
370 _wait(want_token=1, max_delay=max_delay)
371 if _mytokens >= 1:
372 break
373 assert _mytokens < 1
374 b = _try_read(_tokenfds[0], 1)
375 if b == '':
376 raise Exception('unexpected EOF on token read')
377 if b:
378 _mytokens += 1
379 _debug('(%r) got a token (%r).\n' % (reason, b))
380 break
381 if max_delay != None:
382 break
383 assert _mytokens <= 1
384
385
386def ensure_token_or_cheat(reason, cheatfunc):

Callers 1

ensure_token_or_cheatFunction · 0.85

Calls 3

_debugFunction · 0.85
_waitFunction · 0.85
_try_readFunction · 0.85

Tested by

no test coverage detected