async def test_03_set_task_name_without_hierarchy(self, task): set_task_name(task, "HelloWorld", include_hierarchy=False) if supports_task_name(): assert task.get_name() == get_task_name( task) == "Task-99_HelloWorld" else: assert str(id(task)) == get_task_name(task)
def finish_connection(self, exc: Optional[BaseException]) -> None: if self._adaptor: self._adaptor.logger.info('Finishing connection') self._delete_connection() self._status.set_stopping() close_task = create_task(self._close(exc)) set_task_name(close_task, f"Close:{self.peer}")
async def test_04_set_task_name_include_hierarchy(self, task): # Following line required to change task name, pycharm gives error if task is not retrieved _ = self._prepare_current_task('Task-10') set_task_name(task, "HelloWorld") if supports_task_name(): assert task.get_name() == get_task_name( task) == "Task-10:Task-99_HelloWorld" else: assert str(id(task)) == get_task_name(task) await task
def context(self) -> Optional[SSLContext]: if self.ssl: self.logger.info("Setting up SSL") context = SSLContext(PROTOCOL_TLS) if self.cert and self.key: self.logger.info("Using SSL Cert: %s", self.cert) try: context.load_cert_chain(str(self.cert), str(self.key), password=self.key_password) except FileNotFoundError as e: raise FileNotFoundError( better_file_not_found_error( self.cert, self.key, purpose='ssl cert loading')) if self.warn_if_expires_before_days: self._warn_expiry_task = create_task( self.check_cert_expiry()) set_task_name(self._warn_expiry_task, 'CheckSSLCertValidity') context.verify_mode = CERT_REQUIRED if self.cert_required else CERT_NONE context.check_hostname = self.check_hostname self.logger.info('%s, Check Hostname: %s' % (context.verify_mode, context.check_hostname)) if context.verify_mode != CERT_NONE: if self.cafile or self.capath or self.cadata: locations = { 'cafile': str(self.cafile) if self.cafile else None, 'capath': str(self.capath) if self.capath else None, 'cadata': self.cadata } try: context.load_verify_locations(**locations) self.logger.info("Verifying SSL certs with: %s", locations) except FileNotFoundError: raise FileNotFoundError( better_file_not_found_error( *locations.values(), purpose='CA ssl cert validation')) else: context.load_default_certs(self.purpose) self.logger.info("Verifying SSL certs with: %s", get_default_verify_paths()) self.logger.info("SSL Context loaded") # OpenSSL 1.1.1 keylog file if hasattr(context, 'keylog_filename'): keylogfile = os.environ.get('SSLKEYLOGFILE') if keylogfile and not sys.flags.ignore_environment: self.logger.warning( "TLS encryption secrets are being stored in %s", keylogfile) context.keylog_filename = keylogfile return context return None
def create_task(self, coro: Awaitable, name: str = None, include_hierarchy: bool = True, separator: str = ':', continuous: bool = False) -> asyncio.Future: self._counter.increment() task = create_task(coro) set_task_name(task, name, include_hierarchy=include_hierarchy, separator=separator) if not continuous: self._current_tasks.append(task) return task
async def process_msgs(self, msgs: AsyncIterator[MessageObjectType], buffer: bytes) -> None: tasks = [] try: async for msg_obj in msgs: if not self.action.filter(msg_obj): task = create_task(self._process_msg(msg_obj)) set_task_name(task, f'Process {msg_obj}') tasks.append(task) else: self.logger.on_msg_filtered(msg_obj) await asyncio.wait_for(asyncio.gather(*tasks), timeout=self.action.task_timeout) except Exception as exc: self._on_decoding_error(buffer, exc) raise
def call_coro_periodic(self, interval: Union[int, float], async_callback: Callable, *args, fixed_start_time: bool = False, immediate: bool = False, task_name: str = None, **kwargs) -> None: start_time_interval = self.get_start_interval(fixed_start_time, immediate, interval) task = create_task( self._call_coro_periodic(interval, async_callback, start_time_interval=start_time_interval, *args, **kwargs)) set_task_name(task, task_name) self._periodic_tasks.append(task)
def __post_init__(self): self.path.parent.mkdir(parents=True, exist_ok=True) self._task = create_task(self.manage()) set_task_name(self._task, f"ManagedFile:{self.path.name}")