title: Debugging an async program in the pycharm debugger
body: <p>My request is to get debugging data from the debugger and pycharm prompt:</p>
  
  <p>Lets say I have an-old-style python synchronous program with a bug:</p>
  
  <pre><code>   def listdir(self, remote_path):
           with ssh.connect(self.connection_settings['host'], username=self.connection_settings['username'],
                                      password=self.connection_settings['password']) as conn:
              with conn.start_sftp_client() as sftp:
                  sftp.chdir(remote_path) # breakpoint here
  
                  files = sftp.readdir()
                  files_name = [file.filename for file in files]
  
                  return files_name
  
  </code></pre>
  
  <p>I would stop it, go to the debugger, click on debugger console->show python prompt
  and then debug my issues in runtime:</p>
  
  <pre><code>&gt; sftp.getcwd()
  bad_user_location
  &gt; sftp.chdir(good_base_location)
  &gt; sftp.readdir()
  </code></pre>
  
  <p>Just rewriting the code on the fly and testing state and runtime. (This has allways been how I debug, using the <code>immediate window</code> in Microsoft langauges development, and REPL in python and other script languages.</p>
  
  <p>Now I have an async program:</p>
  
  <pre><code>  async def listdir(self, remote_path):
          async with asyncssh.connect(self.connection_settings['host'], username=self.connection_settings['username'],
                                      password=self.connection_settings['password']) as conn:
              async with conn.start_sftp_client() as sftp:
                  await sftp.chdir(remote_path)  # breakpoint here
  
  
                  files = await sftp.readdir()
                  files_name = [file.filename for file in files]
  
                  return files_name
  
  </code></pre>
  
  <p>I stop it, go to the debugger, click on debugger console->show python prompt
  and then debug my issues in runtime:</p>
  
  <pre><code>&gt; sftp.getcwd()
  &lt;CoroWrapper SFTPClient.getcwd() running at....truncated info
  </code></pre>
  
  <ol>
  <li>I try getting the event loop and running on it, but i cannot await without a function.</li>
  <li>I installed IPython 7 that allows event_loop, but it wont run the task, just add to the event loop, as its built for jupyter and not this usecase</li>
  <li>I tried creating a new event loop but there can be only one in a thread.</li>
  <li>I tried using nest_asyncio and apply, but ><code>nest_asyncio.events.new_event_loop().create_task(sftp.getcwd())</code>
  but it just adds it to the loop, it doesnt run it. <code>&lt;Task pending coro=&lt;SFTPClient.getcwd() running at...</code></li>
  <li>I think my best bet is to create a second thread, create a new loop there, and await tasks from that loop. something like <a href="https://stackoverflow.com/questions/31623194/asyncio-two-loops-for-different-i-o-tasks">question about 2 loops</a> but I am having difficulties with this.
  something like:</li>
  </ol>
  
  <pre><code>   &gt;d.run_sync(sftp.getcwd())
     directory_name
     &gt;d.run_sync(sft.chdir(somewhere_else))
     0 # exit code
  </code></pre>
  
  <p>I found in channels v2.0 something like this under <a href="https://www.aeracode.org/2018/02/19/python-async-simplified/" rel="noreferrer">Andrew Gadwins great article</a></p>
  
  <pre><code>   &gt;asgiref.sync.async_to_sync(sftp.getcwd())
     &gt;&lt;asgiref.sync.AsyncToSync object at 0x7ff94c7b37e0&gt; ... created at &lt;input&gt;:1&gt; was never yielded from
     &gt;ERROR:asyncio:&lt;CoroWrapper SFTPClient.getcwd()
  </code></pre>
  
  <ol start="7">
  <li>Maybe I could attach jupyternotebook to my running debugger, but this would be my last resort as it's not really a good maintainable solution </li>
  </ol>
  
  <p>I think its vital to be able to debug coroutines at runtime so i value your solutions greatly.</p>
  
  <p>Thanks</p>