小编Mik*_*eyB的帖子

我应该总是使用pillar.get而不是支柱['foo']吗?

我在支柱文档中看到有两种方法可以在SLS中引用支柱数据.

{{ pillar['foo'] }}
Run Code Online (Sandbox Code Playgroud)

{{ salt['pillar.get']('foo') }}
Run Code Online (Sandbox Code Playgroud)

pillar.get方法更好地处理嵌套的柱状数据,并允许在柱子中找不到数据时指定默认值.但它有点打字,我发现第一种方法更容易阅读.

因此,最好的做法是始终使用pillar.get方法或使用柱['foo']可接受,特别是在处理非嵌套柱数据时.

我怀疑总是使用pillar.get方法是最好的,因为在处理嵌套的柱状数据时使用它或者你想设置默认值是有意义的.并且最好只为您提供一种方法.但我想得到其他人的想法.

Thansk,乔

salt-stack

12
推荐指数
2
解决办法
7587
查看次数

正确使用linux inotify - 每次都重启?

我正在调试客户在其生产系统上遇到的系统负载问题,并且他们已经创建了一个模拟负载的测试应用程序来重现问题:

性感的图

在这个特定的工作量中,编码器所做的一件事就是:

while(1)
  initialize inotify
  watch a directory for events
  receive event
  process event
  remove watch
  close inotify fd
Run Code Online (Sandbox Code Playgroud)

奇怪的是,高系统负载来自close()inotify fd:

inotify_init()                          = 4 <0.000020>
inotify_add_watch(4, "/mnt/tmp/msys_sim/QUEUES/Child_032", IN_CREATE) = 1 <0.059537>
write(1, "Child [032] sleeping\n", 21)  = 21 <0.000012>
read(4, "\1\0\0\0\0\1\0\0\0\0\0\0\20\0\0\0SrcFile.b8tlfT\0\0", 512) = 32 <0.231012>
inotify_rm_watch(4, 1)                  = 0 <0.000044>
close(4)                                = 0 <0.702530>
open("/mnt/tmp/msys_sim/QUEUES/Child_032", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4 <0.000031>
lseek(4, 0, SEEK_SET)                   = 0 <0.000010>
getdents(4, /* 3 entries */, 32768)     = 88 <0.000048>
getdents(4, /* 0 entries …
Run Code Online (Sandbox Code Playgroud)

linux redhat inotify

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

参数化'SELECT IN(...)'查询

我想使用MySQLdb创建参数化查询,例如:

serials = ['0123456', '0123457']
c.execute('''select * from table where key in %s''', (serials,))
Run Code Online (Sandbox Code Playgroud)

但最终被发送到DBMS的是:

select * from table where key in ("'0123456'", "'0123457'")
Run Code Online (Sandbox Code Playgroud)

是否可以像这样创建参数化查询?或者我是否必须循环自己并构建结果集?

注意:executemany(...)不适用于此 - 它只返回最后一个结果:

>>> c.executemany('''select * from table where key in (%s)''',
        [ (x,) for x in serials ] )
2L
>>> c.fetchall()
((1, '0123457', 'faketestdata'),)
Run Code Online (Sandbox Code Playgroud)

改编自Gareth巧妙答案的最终解决方案:

# Assume check above for case where len(serials) == 0
query = '''select * from table where key in ({0})'''.format(
    ','.join(["%s"] * len(serials)))
c.execute(query, tuple(serials)) # tuple() for …
Run Code Online (Sandbox Code Playgroud)

python mysql

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

pyqtgraph:为图中的线添加图例

我正在使用pyqtgraph,我想在InfiniteLines的图例中添加一个项目.

我已经调整了示例代码来演示:

# -*- coding: utf-8 -*-
"""
Demonstrates basic use of LegendItem

"""
import initExample ## Add path to library (just for examples; you do not need this)

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: Legend')
plt.addLegend()

c1 = plt.plot([1,3,2,4], pen='r', name='red plot')
c2 = plt.plot([2,1,4,3], pen='g', fillLevel=0, fillBrush=(255,255,255,30), name='green plot')
c3 = plt.addLine(y=4, pen='y')
# TODO: add legend item indicating "maximum value"

## Start Qt event loop unless running in interactive …
Run Code Online (Sandbox Code Playgroud)

python pyqtgraph

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

创建任意数据和大小的tar流

我需要创建一个任意大的tarfile进行测试,但不希望它打到磁盘上.

最简单的方法是什么?

tar

3
推荐指数
1
解决办法
956
查看次数

标签 统计

python ×2

inotify ×1

linux ×1

mysql ×1

pyqtgraph ×1

redhat ×1

salt-stack ×1

tar ×1