Repository: xonsh/xonsh

Issue:
'Window' object has no attribute 'children'
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.9.24               |
| Git SHA          | 74543ea9             |
| Commit Date      | Oct 10 15:12:47 2020 |
| Python           | 3.8.6                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.3                |
| shell type       | prompt_toolkit       |
| pygments         | 2.7.2                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | manjaro              |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| on jupyter       | False                |
| jupyter kernel   | None                 |
| xontrib 1        | abbrevs              |
| xontrib 2        | argcomplete          |
| xontrib 3        | autovox              |
| xontrib 4        | back2dir             |
| xontrib 5        | cmd_done             |
| xontrib 6        | hist_navigator       |
| xontrib 7        | jedi                 |
| xontrib 8        | kitty                |
| xontrib 9        | pdb                  |
| xontrib 10       | prompt_ret_code      |
| xontrib 11       | vox                  |
| xontrib 12       | voxapi               |
+------------------+----------------------+
```

</details>

## Expected Behavior
interactive shell runs without any error

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->
I get the above error randomly when `$UPDATE_COMPLETIONS_ON_KEYPRESS = True`

### Traceback (if applicable)

<details>

```
2020-11-08 22:06:05.995 | INFO     | xonsh.ptk_shell.completer:reserve_space:118 - 8735829483909
2020-11-08 22:06:06.000 | ERROR    | xonsh.ptk_shell.completer:reserve_space:126 - 'Window' object has no attribute 'children'
Traceback (most recent call last):

  File "/usr/lib/python3.8/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x7f1f895e01f0>
    └ <Thread(ThreadPoolExecutor-1_0, started daemon 139773312693824)>
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x7f1f895dfee0>
    └ <Thread(ThreadPoolExecutor-1_0, started daemon 139773312693824)>
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(ThreadPoolExecutor-1_0, started daemon 139773312693824)>
    │    │        │    └ (<weakref at 0x7f1f803ed270; to 'ThreadPoolExecutor' at 0x7f1f81e857c0>, <_queue.SimpleQueue object at 0x7f1f82a8b2c0>, None,...
    │    │        └ <Thread(ThreadPoolExecutor-1_0, started daemon 139773312693824)>
    │    └ <function _worker at 0x7f1f81edb670>
    └ <Thread(ThreadPoolExecutor-1_0, started daemon 139773312693824)>
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 80, in _worker
    work_item.run()
    │         └ <function _WorkItem.run at 0x7f1f81edb790>
    └ <concurrent.futures.thread._WorkItem object at 0x7f1f803eb460>
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
             │    │   │    │       │    └ {}
             │    │   │    │       └ <concurrent.futures.thread._WorkItem object at 0x7f1f803eb460>
             │    │   │    └ [<function generator_to_async_generator.<locals>.runner at 0x7f1f81f13e50>]
             │    │   └ <concurrent.futures.thread._WorkItem object at 0x7f1f803eb460>
             │    └ <built-in method run of Context object at 0x7f1f8039c9c0>
             └ <concurrent.futures.thread._WorkItem object at 0x7f1f803eb460>
  File "/home/noor/.config/xonsh/.venv/lib/python3.8/site-packages/prompt_toolkit/eventloop/async_generator.py", line 43, in runner
    for item in get_iterable():
                └ <function ThreadedCompleter.get_completions_async.<locals>.<lambda> at 0x7f1f81f13ee0>

  File "/home/noor/.config/xonsh/xsh-src/xonsh/ptk_shell/completer.py", line 73, in get_completions
    self.reserve_space()
    │    └ <function PromptToolkitCompleter.reserve_space at 0x7f1f82aa4430>
    └ <xonsh.ptk_shell.completer.PromptToolkitCompleter object at 0x7f1f82aed8e0>

> File "/home/noor/.config/xonsh/xsh-src/xonsh/ptk_shell/completer.py", line 123, in reserve_space
    hash(app.layout.container.children[0].content.children[1].content)
         │   │      └ Window(content=FormattedTextControl(HTML('No layout specified. Press <reverse>ENTER</reverse> to quit.')))
         │   └ Layout(Window(content=FormattedTextControl(HTML('No layout specified. Press <reverse>ENTER</reverse> to quit.'))), current_wi...
         └ <prompt_toolkit.application.dummy.DummyApplication object at 0x7f1f803eb8b0>

AttributeError: 'Window' object has no attribute 'children'

```

</details>

## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->
1. it happens randomly. sometime doing simple `ls -a` triggers the error

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/xonsh/ptk_shell/completer.py b/xonsh/ptk_shell/completer.py
--- a/xonsh/ptk_shell/completer.py
+++ b/xonsh/ptk_shell/completer.py
@@ -110,7 +110,7 @@ def reserve_space(self):
         """Adjust the height for showing autocompletion menu."""
         app = get_app()
         render = app.renderer
-        window = app.layout.container.children[0].content.children[1].content
+        window = app.layout.current_window
 
         if window and window.render_info:
             h = window.render_info.content_height


Test patch: