小编Dav*_*ave的帖子

忽略__attribute __((packed))在SWIG接口中始终是安全的吗?

由于SWIG无法解析__attribute__((packed))我想要包装的一些C结构,我通过放置一个来解决这个问题

#define __attribute__(x)
Run Code Online (Sandbox Code Playgroud)

在我的.i档案中.

什么时候会来咬我?

swig

6
推荐指数
1
解决办法
868
查看次数

在脚本中使用Matplotlib的渲染器问题

我已经缩小到这个电话:

fig.canvas.tostring_argb() #fig=matplotlib.pyplot.figure()
Run Code Online (Sandbox Code Playgroud)

AttributeError当我将代码作为python脚本运行时,此函数引发了一个问题. AttributeError: 'FigureCanvasGTKAgg' object has no attribute 'renderer'

但是,如果在ipython --pylab命令行中运行,此代码可以正常工作.

据我所知,文档中的Agg渲染器应该可以正常工作.

上下文是我试图从数字制作电影,而不是将帧保存到磁盘; 按照这个问题.我正在使用流式传输像素数组的方法ffmpeg(作为一个单独的进程运行)来执行此操作,我需要argb帧中的值数组.

我是否可以通过一些配置设置让matplotlib在脚本中正常工作?

编辑use('Agg')根据评论 尝试; 仍然失败; 这是一个最小的工作示例.

[dave@dave tools]$ python -c "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot; fig=matplotlib.pyplot.figure(); fig.canvas.tostring_argb()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 416, in tostring_argb
    return self.renderer.tostring_argb()
AttributeError: FigureCanvasAgg instance has no attribute 'renderer'
Run Code Online (Sandbox Code Playgroud)

python matplotlib

6
推荐指数
2
解决办法
3813
查看次数

python (2.7) 中的守护线程是如何被杀死的

当主线程退出时,守护线程会发生什么?他们是如何关闭的?有没有办法确保执行清理代码?

这是我遇到的情况的草图:

import os
import subprocess
import threading
import glob
import datetime

def do_big_job(result='result.txt'):
    tmpfile = result+'.tmp'
    err = subprocess.call(['my_time_consuming_script', '-o', tmpfile])
    if err == 0:
        os.rename(tmpfile, result)
    else:
        os.remove(tmpfile) # process failed, clean up temp file



def main():
    not_done = True
    update = 0
    while not_done:

        # we can see if new data are available,
        # and start a process to get/prep it
        if new_data_available():
            args = ('result{0:05}.txt'.format(update),)
            th = threading.Thread(target=do_big_job, args=args)
            update = update + 1
            th.daemon = …
Run Code Online (Sandbox Code Playgroud)

multithreading python-2.7

6
推荐指数
1
解决办法
2216
查看次数

在 docker 中使用 Secrets 没问题,但对于 docker-compose 则失败

我有一个Dockerfile使用秘密的,我可以使用 成功构建图像docker build。但是,当我尝试使用构建相同的图像时,docker-compose build出现错误:

ERROR: Dockerfile parse error line 4: Unknown flag: mount
Run Code Online (Sandbox Code Playgroud)

这种情况发生在 Ubuntu 20.04LTS(Docker 版本 18.09.6,内部版本 481bc77,docker-compose 版本 1.20.0-rc2,内部版本 8c4af54)上。

在 RHEL 7.9(Docker 版本 20.10.7 版本 f0df350、docker-compose 版本 1.29.2、版本 5becea4c)上,会出现不同的错误:

[2/2] RUN --mount=type=secret,id=the_secret cat /run/secrets/the_secret:  
 #8 0.466 cat: /run/secrets/the_secret: No such file or directory
Run Code Online (Sandbox Code Playgroud)

如何使用 docker-compose 构建涉及机密的镜像?

使用 docker 构建(有效)

#!/bin/bash
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1


echo "I have a secret" > secret.txt
docker build --secret id=the_secret,src=./secret.txt .
Run Code Online (Sandbox Code Playgroud)

使用 docker-compose 构建(失败) …

docker docker-compose docker-secrets

6
推荐指数
0
解决办法
2434
查看次数

设置每个实例 __call__ 的方法?

我想做的是这样的:

class Foo(object):
    def __init__(self):
        pass
    def f(self):
        print "f"
    def g(self):
        print "g"


# programatically set the "default" operation
fer=Foo()
fer.__call__=fer.f

# a different instance does something else as its
# default operation
ger=Foo()
ger.__call__=ger.g

fer()  # invoke different functions on different
ger()  # objects depending on how they were set up.
Run Code Online (Sandbox Code Playgroud)

但从 2.7(我目前正在使用)开始,我无法执行此操作,尝试fer() 引发异常。

实际上,有没有办法设置每个实例的__call__方法?

python

5
推荐指数
1
解决办法
728
查看次数

有没有理由使用香草纯数据代替Pd扩展?

我刚刚开始使用Pd,想知道在使用Pd vanillavs. 时选择哪些因素Pd-extended.

puredata

5
推荐指数
1
解决办法
3045
查看次数

如何在面向对象的Matlab中定义派生属性

我想要一个我可以访问的只读字段fv=object.field,但返回的值是从对象的其他字段计算的(即返回值满足fv==f(object.field2)).

所需的功能与propertyPython中的function/decorator 相同.

我记得看到一个参考,通过设置properties块的参数这是可能的,但Matlab OOP文档是如此分散,我再也找不到它.

oop matlab

5
推荐指数
1
解决办法
408
查看次数

Emacs org-mode python块有5个空格标签,但我想要4个空格标签

我在组织模式文件中的源块内编写python代码; 我正在使用emacs命令在python模式下在子缓冲区中编辑代码块C-c '

例:

#+begin_src python
def function(x):
     hitting_tab_inserts_5_spaces=x*2
     if x<0:
          hitting_tab_inserts_5_spaces=-x
     return x
Run Code Online (Sandbox Code Playgroud)

我到处都有5个空格标签,而不是我想要的4个空格标签.

注意:我有v蛇(vim仿真).

配置中的哪些参数会影响org-mode文件中代码块内的列表?

如果我.py使用emacs 编辑文件,我会得到4个空格的标签; 这个5空格的标签只发生在org-mode中.

python emacs tabs indentation org-mode

5
推荐指数
1
解决办法
506
查看次数

Python 术语:接口与协议

有人可以解释一下Python 编程中协议接口这两个术语的区别吗?

我在缓冲协议PEP 544等内容中看到对术语“协议”的引用,但想确保我理解这个术语的含义,以及何时何地,您会以不同于一般概念的方式使用它一个“接口”。

python terminology

5
推荐指数
1
解决办法
2725
查看次数

当前“kubectl run --generator=run/v1”的等价物是什么

我正在研究Kubernetes in Action(版权所有 2018),至少其中一个示例相对于当前版本的kubectl.

目前我陷入了第 2.3 节,只是试图演示一个简单的 Web 服务器 docker 容器(“kubia”):

kubectl run kubia --image=Dave/kubia --port=8080 --generator=run/v1
Run Code Online (Sandbox Code Playgroud)

--generator选项已从当前版本的kubectl. 在当前版本的 中哪些命令可以达到相同的目的kubectl

注意:我实际上只学习了 2 章 Kubernetes,所以我真的不知道什么是部署或其他任何东西(所以官方 Kubernetes 文档没有帮助),我只需要最简单的方法来验证我是否事实上,可以在我的 minikube“集群”中运行这个容器。

kubernetes

5
推荐指数
1
解决办法
1597
查看次数