python中内存高效的2d可扩展数组?(Memory-efficient 2d growable array in python?)
我正在开发一个处理大量数据的应用程序。
....并继续运行我的计算机内存。 :(
Python在变量上有大量的内存开销(根据sys.getsizeof())。 例如,一个带有一个整数的基本元组占用56个字节。 一个空列表,64个字节。 严重的开销。
Numpy数组非常适合减少开销。 但它们并不是为了有效增长而设计的(参见最快的方法来增长一个数字阵列 )。 数组( https://docs.python.org/3/library/array.html )似乎很有希望,但它是1d。 我的数据是2d,一个数组的行数任意,列宽度为3个浮点数(理想情况下为float32),另一个数据的列宽为2个整数(理想情况下为uint32)。 显然,使用~80字节的python结构来存储每行12或8个字节的数据将占用我的内存消耗总量。
在Python中将内存使用率保持为“假”2d的唯一现实方法,即将数组作为arr [row * WIDTH + column]并将行计为len(arr)/ WIDTH?
I'm working on an app that processes a lot of data.
.... and keeps running my computer out of memory. :(
Python has a huge amount of memory overhead on variables (as per sys.getsizeof()). A basic tuple with one integer in it takes up 56 bytes, for example. An empty list, 64 bytes. Serious overhead.
Numpy arrays are great for reducing overhead. But they're not designed to grow efficiently (see Fastest way to grow a numpy numeric array). Array (https://docs.python.org/3/library/array.html) seems promising, but it's 1d. My data is 2d, with an arbitrary number of rows and a column width of 3 floats (ideally float32) for one array, and a column width of two ints (ideally uint32) for the other. Obviously, using ~80 bytes of python structure to store 12 or 8 bytes of data per row is going to total my memory consumption.
Is the only realistic way to keep memory usage down in Python to "fake" 2d, aka by addressing the array as arr[row*WIDTH+column] and counting rows as len(arr)/WIDTH?
原文:https://stackoverflow.com/questions/45250182
最满意答案
通过执行解析到shell
cron-launcher.sh
的第二个参数解决了该问题fac是命令从cron
echo "toto" >> /tmp/shell.log
SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log
在shell
cron-launcher
被解析为$2
。因此我必须修改我的代码,如下所示:
#!/bin/bash #Script use to launch cron tasks SHELL="/bin/bash" LOGDIR="/var/log/cronlauncher/" #echo "$USER" >> /tmp/test.log COMMAND="$2" eval $COMMAND
The issue was solved by executing the 2nd argument parsed to the shell
cron-launcher.sh
The fac is that the command
echo "toto" >> /tmp/shell.log
from the cron
SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log
is parsed as
$2
in the shellcron-launcher
.Hence I juste had to modify my code as follows:
#!/bin/bash #Script use to launch cron tasks SHELL="/bin/bash" LOGDIR="/var/log/cronlauncher/" #echo "$USER" >> /tmp/test.log COMMAND="$2" eval $COMMAND
相关问答
更多-
看看django的自定义管理命令 。 作为一个基本的例子: from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User from perfil.models import * class Command(BaseCommand): help = 'What does this do? ' def handle(self, *ar ...
-
通过执行解析到shell cron-launcher.sh的第二个参数解决了该问题 fac是命令从cron echo "toto" >> /tmp/shell.log SHELL=/bin/cron-launcher.sh * * * * * test echo "toto" >> /tmp/shell.log 在shell cron-launcher被解析为$2 。 因此我必须修改我的代码,如下所示: #!/bin/bash #Script use to launch cron tasks SHELL ...
-
没有任何选项的命令crontab从stdin安装crontab。 如果需要附加到旧的crontab, crontab -l将返回当前的crontab。 The command crontab without any options installs a crontab from stdin. crontab -l returns the current crontab if you need to append to the old crontab.
-
Cron作业与shell脚本(Cron job with shell script)[2023-07-26]
如评论中所述,出现以下错误: E486:找不到图案:2 * * * * 是因为你没有正确编辑而造成的。 也就是说,你正确地说crontab -e然后你进入vi 。 您可以直接键入*/2 * * * * /home/test/test/test.sh ,而不是进入插入模式, vi会尝试将其作为命令执行,而不是。 所以你要做的就是按i进入写入模式。 然后,就在那时,写下*/2 * * * * /home/test/test/test.sh 。 最后,通过说:wq保存文件。 如果您的cronjob中出现其他问题, ... -
Cron(至少在Debian中)不会执行超过1个硬链接的crontabs,请参阅错误647193 。 由于Docker使用覆盖,所以导致多个链接指向文件,因此您必须在启动脚本中touch它,以便链接被切断: touch /etc/crontab /etc/cron.*/* Cron (at least in Debian) does not execute crontabs with more than 1 hardlink, see bug 647193. As Docker uses overlays ...
-
在虚拟环境中使用cron安排django自定义命令(schedule django custom commands with cron inside a virtualenvironment)[2022-08-13]
在这种情况下,您无需激活virtualenv。 你可以在virtualenv的bin目录中使用python。 */10 * * * * source /home/username/Envs/project_name/bin/python /home/username/Code/project_name/manage.py post_message > /dev/null You don't need to activate the virtualenv in this case. You can just ... -
我读了你的评论,你绝对应该在尝试安排它之前让它手动运行。 从php配置获取信息: 要找出which php安装路径,对于版本php -v 最后确保脚本是可执行的chmod +x /home/eem/cars1/cron/cronjob1.php I finally managed to find out what is wrong with the code. It turned out the ADOdb libraries are not suppor ...
-
使用这里的帮助,无论出于何种原因,即使我有正确的代码使脚本可执行,这条线似乎没有在我的部署脚本中触发,这意味着我所要做的就是之后运行它来制作它可执行,然后一切正常。 获得的经验:如果您需要这样做,上面的代码可以正常工作 Using the help from here, for whatever reason, even though I had the code correct to make the script executable, this line didn't seem to fire in ...
-
无法通过OpsWorks找到由Chef自定义配方创建的cron作业(Can't find cron job created by Chef custom recipe through OpsWorks)[2021-12-30]
也许在/etc/cron.d/my_cron_job ? 我假设Chef使用作业名称来创建一个单独的文件,因为它更容易管理它而不是crontab,其他可能是非厨师工作。 Maybe in /etc/cron.d/my_cron_job? I assume Chef uses the job name to create a separate file because it's easier to manage it instead of a crontab where other maybe non-che ... -
Cron不会执行ruby脚本(Cron won't execute ruby script)[2021-08-05]
在你的问题中,你正在运行的cron就像 2 * * * * . $HOME/.bash_profile ~/jek.sh 您需要使用此条目更正/验证多项内容 检查两者的文件权限是777还是775 ( rwx )。 如果没有,则使用chmod 777 ~/jek.sh更改文件权限 检查他们每个人在他们的shebang行中定义他们是哪个语言脚本( #!/usr/local/env sh ) 用&&或;分隔两个脚本 这样它们都能正常运行。 目前,第二个脚本的名称将被视为第一个脚本的参数。 有一个. 在2 * * ...