(self, **kwargs)
| 496 | |
| 497 | @dispatches_events('client_init') |
| 498 | def __init__(self, **kwargs): |
| 499 | logger.debug("Client init called with: %r", kwargs) |
| 500 | |
| 501 | self._closed = False |
| 502 | self._closing = False |
| 503 | self._close_lock = threading.Lock() |
| 504 | self._jobs = self._WaitableCounter() |
| 505 | |
| 506 | # derive instance-level defaults from class defaults and init defaults |
| 507 | self.defaults = copy.deepcopy(self.DEFAULTS) |
| 508 | user_defaults = kwargs.pop('defaults', None) |
| 509 | if user_defaults is None: |
| 510 | user_defaults = {} |
| 511 | update_config(self.defaults, user_defaults) |
| 512 | |
| 513 | # combine instance-level defaults with file/env/kwarg option values |
| 514 | # note: treat empty string values (e.g. from file/env) as undefined/None |
| 515 | options = copy.deepcopy(self.defaults) |
| 516 | update_config(options, kwargs) |
| 517 | logger.debug("Client options over defaults: %r", options) |
| 518 | |
| 519 | self.config: ClientConfig = validate_config_v1(options) |
| 520 | logger.debug("Validated client config=%r", self.config) |
| 521 | |
| 522 | # resolve endpoints using region |
| 523 | resolve_endpoints(self.config, inplace=True) |
| 524 | logger.debug("Final client config=%r", self.config) |
| 525 | |
| 526 | # sanity check |
| 527 | if not self.config.endpoint: |
| 528 | raise ValueError("API endpoint not defined") |
| 529 | |
| 530 | if not self.config.token: |
| 531 | raise ValueError("API token not defined") |
| 532 | |
| 533 | # Build the problem submission queue, start its workers |
| 534 | self._submission_queue = queue.Queue() |
| 535 | self._submission_workers = [] |
| 536 | for _ in range(self._SUBMISSION_THREAD_COUNT): |
| 537 | worker = threading.Thread(target=self._do_submit_problems) |
| 538 | worker.daemon = True |
| 539 | worker.start() |
| 540 | self._submission_workers.append(worker) |
| 541 | |
| 542 | # Build the cancel problem queue, start its workers |
| 543 | self._cancel_queue = queue.Queue() |
| 544 | self._cancel_workers = [] |
| 545 | for _ in range(self._CANCEL_THREAD_COUNT): |
| 546 | worker = threading.Thread(target=self._do_cancel_problems) |
| 547 | worker.daemon = True |
| 548 | worker.start() |
| 549 | self._cancel_workers.append(worker) |
| 550 | |
| 551 | # Build the problem status polling queue, start its workers |
| 552 | self._poll_queue = queue.PriorityQueue() |
| 553 | self._poll_workers = [] |
| 554 | for _ in range(self._POLL_THREAD_COUNT): |
| 555 | worker = threading.Thread(target=self._do_poll_problems) |
nothing calls this directly
no test coverage detected