python - 在 Mac 上将文件复制到 RAM (Python)

标签 python linux macos unix conv-neural-network

我正在运行另一个用户的一些代码来构建一个卷积网络。一个早期的函数试图通过运行将训练和测试图像复制到 /dev/shm:

import os
import time

paths = ["data/raw/images_train_rev1", "data/raw/images_test_rev1"]

for path in paths:
    if os.path.exists(os.path.join("/dev/shm",os.path.basename(path))):
        print "%s exists in /dev/shm, skipping." % path
        continue

    print "Copying %s to /dev/shm..." % path
    start_time = time.time()
    os.system("cp -R %s /dev/shm/" % path)
    print "  took %.2f seconds." % (time.time() - start_time)

我收到错误:

cp: /dev/shm: Permission denied
cp: data/raw/images_test_rev1: unable to copy extended attributes to 
/dev/shm: No such file or directory

有没有可以在我的 Mac 上使用的 /dev/shm 的替代品?


我已经使用这些信息在 OSX 中创建了一个 ramdisk:

http://osxdaily.com/2007/03/23/create-a-ram-disk-in-mac-os-x/

然后: ls -lah/dev/rdisk1 crw-------- 1 xxxx staff 1, 4 27 May 16:26/dev/rdisk1

但是,当我尝试写入时出现错误:

/rdisk1 is not a directory
took 0.78 seconds.
Copying data/raw/images_test_rev1 to /dev/rdisk1...
cp: /dev/rdisk1 is not a directory
took 0.02 seconds.

希望能帮到你。谢谢。

最佳答案

您可以使用此实用程序 https://gist.github.com/koshigoe/822455

cd /tmp
git clone https://gist.github.com/822455.git
cd 822455
chmod +x *
sudo ./mount-ram.sh /dev/shm 1024 
sudo chmod 777 /dev/shm

它将在RAM中创建一个1G的可写/dev/shm文件夹

关于python - 在 Mac 上将文件复制到 RAM (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30474044/

相关文章:

Python:用于快速全屏 jpg/png 显示的 OSX 库

python - 如何根据 Python 中另一个数据框的关系为变量赋值

python - 如何在 Python 中定义全局函数?

python - 什么是 numpy.fft.rfft 和 numpy.fft.irfft 及其在 MATLAB 中的等效代码

python - 属性和 __getattr__ 与 AttributeError 的兼容性问题

linux - 如何在grep中传递多个变量

c++ - 在运行时检查动态库的兼容性

c - 用于读取堆栈值的 Linux 工具

ios - 在 MacOS/IOS SDK 上强制 SSLv3 连接

python - Tox 总是需要 30 秒才能运行