Mic*_*ein 5 python debugging asynchronous python-multithreading python-asyncio
我的请求是从调试器和 pycharm 提示符中获取调试数据:
假设我有一个带有错误的旧式 python 同步程序:
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
Run Code Online (Sandbox Code Playgroud)
我会停止它,转到调试器,单击调试器控制台-> 显示 python 提示,然后在运行时调试我的问题:
> sftp.getcwd()
bad_user_location
> sftp.chdir(good_base_location)
> sftp.readdir()
Run Code Online (Sandbox Code Playgroud)
只需即时重写代码并测试状态和运行时即可。(这一直是我调试的方式,使用immediate windowMicrosoft 语言开发中的,以及 Python 和其他脚本语言中的 REPL。
现在我有一个异步程序:
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
Run Code Online (Sandbox Code Playgroud)
我停止它,转到调试器,单击调试器控制台-> 显示 python 提示,然后在运行时调试我的问题:
> sftp.getcwd()
<CoroWrapper SFTPClient.getcwd() running at....truncated info
Run Code Online (Sandbox Code Playgroud)
nest_asyncio.events.new_event_loop().create_task(sftp.getcwd())
但它只是将它添加到循环中,它没有运行它。<Task pending coro=<SFTPClient.getcwd() running at... >d.run_sync(sftp.getcwd())
directory_name
>d.run_sync(sft.chdir(somewhere_else))
0 # exit code
Run Code Online (Sandbox Code Playgroud)
我在频道 v2.0 中在Andrew Gadwin 的精彩文章下发现了类似的内容
>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()
Run Code Online (Sandbox Code Playgroud)
我认为能够在运行时调试协同程序至关重要,因此我非常重视您的解决方案。
谢谢
| 归档时间: |
|
| 查看次数: |
805 次 |
| 最近记录: |