小编Coc*_*sin的帖子

在 Python 中管道 SoX - 子进程替代方案?

我在应用程序中使用SoX。应用程序使用它对音频文件应用各种操作,例如修剪。

这工作正常:

from subprocess import Popen, PIPE

kwargs = {'stdin': PIPE, 'stdout': PIPE, 'stderr': PIPE}

pipe = Popen(['sox','-t','mp3','-', 'test.mp3','trim','0','15'], **kwargs)
output, errors = pipe.communicate(input=open('test.mp3','rb').read())
if errors:
    raise RuntimeError(errors)
Run Code Online (Sandbox Code Playgroud)

这将导致大文件出现问题,因为read()将完整文件加载到内存中;这很慢,可能会导致管道缓冲区溢出。存在一种解决方法:

from subprocess import Popen, PIPE
import tempfile
import uuid
import shutil
import os

kwargs = {'stdin': PIPE, 'stdout': PIPE, 'stderr': PIPE}
tmp = os.path.join(tempfile.gettempdir(), uuid.uuid1().hex + '.mp3')

pipe = Popen(['sox','test.mp3', tmp,'trim','0','15'], **kwargs)
output, errors = pipe.communicate()

if errors:
    raise RuntimeError(errors)

shutil.copy2(tmp, 'test.mp3')
os.remove(tmp)
Run Code Online (Sandbox Code Playgroud)

所以问题如下:除了为 Sox C …

python audio subprocess sox inter-process-communicat

4
推荐指数
1
解决办法
9454
查看次数

PostgreSQL范围类型中的NULL与`infinity`

PostgreSQL范围类型中'infinity'的含义是什么?指定infinity-infinity作为绑定有什么区别,或NULL?即,是infinity指定范围界限是无限的显式形式,而NULL隐式指定无限界限范围?

请参阅以下示例:

SELECT tstzrange('-infinity','infinity') && tstzrange(NULL, NULL);
 ?column?
----------
 t

SELECT tstzrange('2013-01-01 00:00:00+01', '2013-02-01 00:00:00+01')
    && tstzrange(NULL, '2013-03-01 00:00:00+01');
 ?column?
----------
 t

SELECT tstzrange('2013-01-01 00:00:00+01', '2013-02-01 00:00:00+01')
    && tstzrange('-infinity', '2013-03-01 00:00:00+01');
 ?column?
----------
 t
Run Code Online (Sandbox Code Playgroud)

postgresql null range infinity postgresql-9.2

4
推荐指数
1
解决办法
4100
查看次数

可能6NF表包含外键吗?

当一个表是外键时,表是否满足6NF?例如:

CREATE TABLE authors(
    author_id serial NOT NULL PRIMARY KEY
);

-- other author attributes

CREATE TABLE books(
    book_id serial NOT NULL PRIMARY KEY
);

CREATE TABLE books_author(
    book_id int NOT NULL PRIMARY KEY REFERENCES books (book_id),
    author_id int NOT NULL REFERENCES authors (author_id)
);
Run Code Online (Sandbox Code Playgroud)

如果不是,模型应如何处理外键关系?

如果M2M的关系,应该如何处理?连接表也应该是6NF吗?

database database-design normalization database-table 6nf

2
推荐指数
1
解决办法
190
查看次数

CQRS /事件来源:如何实施数据完整性?

如果我实现CQRS和事件源,那么假设数据的最终存储(读取存储)在RDBMS中,那么如何保持数据的完整性和一致性?

如果发布事件但由于违反检查或缺少FK引用而RDBMS拒绝从该事件派生的数据怎么办?

cqrs event-sourcing

2
推荐指数
1
解决办法
882
查看次数