My request is to get debugging data from the debugger and pycharm prompt:
Lets say I have an-old-style python synchronous program with a bug:
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
I would stop it, go to the debugger, click on debugger console->show python prompt and then debug my issues in runtime:
> sftp.getcwd()
bad_user_location
> sftp.chdir(good_base_location)
> sftp.readdir()
Just rewriting the code on the fly and testing state and runtime. (This has allways been how I debug, using the immediate window
in Microsoft langauges development, and REPL in python and other script languages.
Now I have an async program:
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
I stop it, go to the debugger, click on debugger console->show python prompt and then debug my issues in runtime:
> sftp.getcwd()
<CoroWrapper SFTPClient.getcwd() running at....truncated info
- I try getting the event loop and running on it, but i cannot await without a function.
- 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
- I tried creating a new event loop but there can be only one in a thread.
- I tried using nest_asyncio and apply, but >
nest_asyncio.events.new_event_loop().create_task(sftp.getcwd())
but it just adds it to the loop, it doesnt run it.<Task pending coro=<SFTPClient.getcwd() running at...
- I think my best bet is to create a second thread, create a new loop there, and await tasks from that loop. something like question about 2 loops but I am having difficulties with this. something like:
>d.run_sync(sftp.getcwd())
directory_name
>d.run_sync(sft.chdir(somewhere_else))
0 # exit code
I found in channels v2.0 something like this under Andrew Gadwins great article
>asgiref.sync.async_to_sync(sftp.getcwd())
><asgiref.sync.AsyncToSync object at 0x7ff94c7b37e0> ... created at <input>:1> was never yielded from
>ERROR:asyncio:<CoroWrapper SFTPClient.getcwd()
- 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
I think its vital to be able to debug coroutines at runtime so i value your solutions greatly.
Thanks