【发布时间】:2021-05-30 21:14:09
【问题描述】:
我正在使用 python,因为我尝试在 for 循环中以冷状态从 psql 运行一些查询。所以在执行每个查询之前,我的缓存必须清除! 我导入了操作系统,然后我这样做了:
if state=="cold":
os.system('sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"')
我得到这个输出:
sh: 1: cannot create /proc/sys/vm/drop_caches: Permission denied
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
我不知道如何解决这个问题。
【问题讨论】:
-
sudo 需要手动输入密码。除非您使用 -S 选项,否则您无法从代码中输入。试试 -S 选项
-
并且您的权限被拒绝,因为您没有从 sudo 提示符输入密码,基本上那不是 sudo
标签: python shell caching psql timescaledb