Python中文
首页
教程
问答
标签
搜索
登录
注册
如何避免[Errno 12]无法分配使用子流程modu导致的内存错误
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p><strong>完成工作测试用例</strong></p> <p>当然,取决于本地和远程计算机上的内存,阵列大小将不同。</p> <pre><code>z1 = numpy.random.rand(300000000,2); for i in range(1000): print('*******************************************\n'); direct_output = subprocess.check_output('ssh blah@blah "ls /"', shell=True); direct_output = 'a'*1200000; a2 = direct_output*10; print(len(direct_output)); </code></pre> <p><strong>当前用例</strong></p> <p>如果它有助于我的用例如下:</p> <p>我发出db查询,然后将结果表存储在远程计算机上。然后我想通过网络传输它们并进行分析。到目前为止,我在python中做了如下工作:</p> <pre><code>#run a bunch of queries before hand with the results in remote files .... counter = 0 mergedDataFrame = None while NotDone: output = subprocess.check_output('ssh blah@blah cat /data/file%08d'%(counter)) data = pandas.read_csv(...) #do lots of analysis, <a href="https://www.cnpython.com/list/append" class="inner-link">append</a>, merge, numpy stuff etc... mergedDataFrame = pandas.merge(...) counter += 1 </code></pre> <p>在某个时刻,我在check_output命令中收到以下错误:[Errno 12]无法分配内存</p> <p><strong>背景</strong></p> <p>多亏了下面的问题,我想我知道出了什么问题。发布了许多解决方案,我正在尝试确定哪些解决方案将避免[Errno 12]无法使用fork/clone分配与子流程实现相关联的内存错误。</p> <p><a href="https://stackoverflow.com/questions/1367373/python-subprocess-popen-oserror-errno-12-cannot-allocate-memory">Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory"</a>这给出了底层诊断,并建议了一些解决方法,如生成单独的脚本等。。。</p> <p><a href="https://stackoverflow.com/questions/15443246/understanding-python-fork-and-memory-allocation-errors">Understanding Python fork and memory allocation errors</a>建议使用rfoo来规避fork/clone的子进程限制,生成子进程和复制内存等。。。这似乎意味着客户机-服务器模型</p> <p><a href="https://stackoverflow.com/questions/1233655/what-is-the-simplest-way-to-ssh-using-python?lq=1">What is the simplest way to SSH using Python?</a>,但是由于内存限制和fork/clone实现,我有额外的约束不能使用subprocess?解决方案建议使用paramiko或在其上构建的东西,其他人建议使用子流程(我发现在我的情况下,子流程不起作用)。</p> <p>还有其他类似的问题,但答案经常提到文件描述符是罪魁祸首(在本例中,它们不是罪魁祸首)、向系统添加更多RAM(我不能这样做)、升级到x64(我已经在x64上了)。一些关于以诺门问题的暗示。一些回答提到试图确定subprocess.Popen(在我的例子中是check_output)是否没有正确地清理进程,但是看起来S.Lott和其他人同意子进程代码本身正在正确地清理。</p> <ul> <li><a href="https://stackoverflow.com/questions/5306075/python-memory-allocation-error-using-subprocess-popen">Python memory allocation error using subprocess.Popen</a></li> <li><a href="https://stackoverflow.com/questions/17471802/python-ioerror-cannot-allocate-memory-although-there-is-plenty">Python IOError cannot allocate memory although there is plenty</a></li> <li><a href="https://stackoverflow.com/questions/9898888/cannot-allocate-memory-on-popen-commands">Cannot allocate memory on Popen commands</a></li> <li><a href="https://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">Python subprocess.Popen erroring with OSError: [Errno 12] Cannot allocate memory after period of time</a></li> </ul> <p>我已经搜索了github<a href="https://github.com/paramiko/paramiko/search?q=Popen&type=Code" rel="noreferrer">https://github.com/paramiko/paramiko/search?q=Popen&type=Code</a>上的源代码,它似乎在proxy.py文件中使用了subprocess。</p> <p><strong>实际问题</strong></p> <p>这是否意味着最终paramiko使用的是上面描述的Popen解决方案,当python内存占用增加并且由于clone/fork实现而重复进行Popen调用时会出现问题?</p> <p>如果paramiko不工作,有没有其他的方法来做我正在寻找的只有客户端的解决方案?还是需要客户机/服务器/套接字解决方案?如果是这样的话,rfoo、tornado或zeromq、http传输会在这里工作吗?</p> <p><strong>注释</strong> 我运行64位linux 8GB主内存。我不想追求购买更多内存的选择。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>如果内存不足,可能是因为子进程试图同时读取太多内存。除了使用重定向到本地文件之外,解决方案可能是将类似popen的功能与stdin/stdout对一起使用,stdin/stdout对可以一次读取一点。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何提高Djang的410误差
4 回答
如何提高doc2vec模型中两个文档(句子)的余弦相似度?
6 回答
如何提高Docker的日志限制?|[输出已剪裁,达到日志限制100KiB/s]
9 回答
如何提高DQN的性能?
2 回答
如何提高EasyOCR的准确性/预测?
5 回答
如何提高Euler#39项目解决方案的效率?
6 回答
如何提高F1成绩进行分类
5 回答
如何提高FaceNet的准确性
2 回答
如何提高fft处理的精度?
9 回答
如何提高Fibonacci实现对大n的精度?
9 回答
如何提高Flask与psycopg2的连接时间
6 回答
如何提高FosterCauer变换的scipy.signal.invres()的数值稳定性?
7 回答
如何提高gae查询的性能?
10 回答
如何提高GANs用于时间序列预测/异常检测的结果
4 回答
如何提高gevent和tornado组合的性能?
4 回答
如何提高googleappengin请求日志的吞吐量
8 回答
如何提高googlevision文本识别的准确性
5 回答
如何提高groupby/apply效率
4 回答
如何提高Gunicorn中的请求率
2 回答
如何提高G中的文件编码转换
10 回答