python - OSError : [Errno 7] Argument list too long on ubuntu, python 使用 popen 调用 bitcoind-cli

标签 python popen bitcoind

在 ubuntu 上使用 popen 运行调用 bitcoind-cli 的 python 脚本,在具有许多事务的大块上,调用 getrawtransaction 时出现错误 OSError: [Errno 7] Argument list too long

我知道这是 shell 和 python 脚本之间的缓冲区问题? 只有一个参数,我想这只是一个很长的参数

我还需要检查其他东西吗? 我可以以某种方式使缓冲区更大,还是应该将与 bitcoind 交互的方法更改为 RPC?

在本地和 AWS ubuntu 机器上试过

谢谢

最佳答案

这是您的操作系统限制,例如:

>>> import os
>>> os.execl('/bin/ls', 'ls', 'c'*10**7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/os.py", line 314, in execl
    execv(file, args)
OSError: [Errno 7] Argument list too long

在您的情况下,是否有必要在命令行上传递数据(您可以使用管道/文件/套接字等代替吗?)?您可以使用拆分的命令行参数多次运行该命令吗?参见 Solving “mv: Argument list too long” .

如果传递的环境太大,你可能会得到同样的错误:

>>> os.execle('/usr/bin/env', 'env', {'envvar': 'c'*10**9})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/os.py", line 322, in execle
    execve(file, args[:-1], env)
OSError: [Errno 7] Argument list too long

解决方案是清理传递的环境以避免未使用的大型环境变量。

The limits might be hardcoded in the kernel source .

关于python - OSError : [Errno 7] Argument list too long on ubuntu, python 使用 popen 调用 bitcoind-cli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26735006/

相关文章:

bitcoin - 连接到硬编码节点后比特币对等发现如何工作?

python - 在 cv2 中使用 skimage 图像

python - 使用 try 语句从嵌套 for 循环写入文件

python - 使用 Paramiko 在 Python 中通过 ssh 实现交互式 shell?

c - 如何从 char * 切换到 const char *[beaglebone 中的 pwm]?

php - Bitcoind rpc AddLocal(ip :port) and Disover: IPv4 eth0: ip missing Amazon AWS CentOS

bitcoin - 在什么情况下比特币的区 block 链大小可以减少?

python - 由 Xarray 中的一系列坐标定义的多边形的 3D 掩模

使用 popen 更改目录

c - 如何检测客户端内部的pclose