MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _initialize

Method _initialize

asyncpg/pool.py:509–540  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

507 self._schedule_min_size_maintenance()
508
509 async def _initialize(self):
510 self._queue = _PoolConnectionHolderQueue(maxsize=self._maxsize)
511 for _ in range(self._maxsize):
512 ch = PoolConnectionHolder(
513 self,
514 max_queries=self._max_queries,
515 max_inactive_time=self._max_inactive_connection_lifetime,
516 setup=self._setup)
517
518 self._holders.append(ch)
519 self._queue.put_nowait(ch)
520
521 if self._initsize:
522 # Since we use a LIFO queue, the first items in the queue will be
523 # the last ones in `self._holders`. We want to pre-connect the
524 # first few connections in the queue, therefore we want to walk
525 # `self._holders` in reverse.
526
527 # Connect the first connection holder in the queue so that
528 # any connection issues are visible early.
529 first_ch = self._holders[-1] # type: PoolConnectionHolder
530 await first_ch.connect()
531
532 if self._initsize > 1:
533 connect_tasks = []
534 for i, ch in enumerate(reversed(self._holders[:-1])):
535 # `initsize - 1` because we already have first_ch
536 if i >= self._initsize - 1:
537 break
538 connect_tasks.append(ch.connect())
539
540 await asyncio.gather(*connect_tasks)
541
542 def _schedule_min_size_maintenance(self):
543 if (not self._initialized or self._initializing or self.is_closing()

Callers 1

_async__init__Method · 0.95

Calls 3

connectMethod · 0.95

Tested by

no test coverage detected