def METHOD_NAME(self, *args: Any, **kwargs: Union[Any, Dict[str, str]]) -> Optional[int]:
    for s in ('stdin', 'stdout', 'stderr'):
        kwargs.pop(s, None)
    communicate: Optional[Dict[str, str]] = kwargs.pop('communicate', None)
    input_data = None
    if isinstance(communicate, dict):
        input_data = communicate.get('input')
        if input_data:
            if input_data[-1] != '\n':
                input_data += '\n'
            input_data = input_data.encode('utf-8')
        kwargs['stdin'] = subprocess.PIPE
        kwargs['stdout'] = subprocess.PIPE
        kwargs['stderr'] = subprocess.PIPE
    try:
        with self._lock:
            if self._is_cancelled:
                raise PostgresException('cancelled')
            self._is_cancelled = False
            started = self._start_process(*args, **kwargs)
        if started and self._process is not None:
            if isinstance(communicate, dict):
                communicate['stdout'], communicate['stderr'] = self._process.communicate(input_data)
            return self._process.wait()
    finally:
        with self._lock:
            self._process = None
        self._kill_children()