我正在使用这样的东西来并行运行测试:
stage('Test') {
steps {
script {
testing_closures = [one: { print("staring one"); sleep 10; print("finishing one") },
two: { print("staring two"); sleep 10; print("finishing two") },
three: { print("staring three"); sleep 10; print("finishing three") },
four: { print("staring four"); sleep 10; print("finishing four") },
five: { print("staring five"); sleep 10; print("finishing five") },
six: { print("staring six"); sleep 10; print("finishing six") }]
parallel(testing_closures)
}
}
}
Run Code Online (Sandbox Code Playgroud)
主要目标是限制那些关闭 - 我不希望它们中的所有六个同时运行 - 一次只有3个.我希望能够运行另一个这样的构建,它也将运行所有这些闭包,但同时只运行3个.
我正在考虑使用节点 - 即在节点{}块中包装每个闭包:
one: { node { print("staring …Run Code Online (Sandbox Code Playgroud) 我偶然发现了真正奇怪的python 3问题,原因我不明白。
我想通过检查所有对象的属性是否相等来比较我的对象。
一些子类将具有包含对绑定到self的方法的引用的字段,这会导致 RecursionError
这是PoC:
class A:
def __init__(self, field):
self.methods = [self.method]
self.field = field
def __eq__(self, other):
if type(self) != type(other):
return False
return self.__dict__ == other.__dict__
def method(self):
pass
first = A(field='foo')
second = A(field='bar')
print(first == second)
Run Code Online (Sandbox Code Playgroud)
在python 3中运行上面的代码会引发问题RecursionError,我不确定为什么。似乎A.__eq__用来比较中保留的功能self.methods。所以我的第一个问题是-为什么?为什么__eq__调用该对象的对象以比较该对象的绑定函数?
第二个问题是- 我__dict__应该使用哪种过滤器来保护__eq__免受此问题的影响?我的意思是-在上方的PoC中,它self.method只是保存在一个列表中,但有时它可能处于另一个结构中。过滤必须包括所有可能包含自引用的容器。
需要澄清的一点是:我确实需要将该self.method函数保留在一个self.methods字段中。这里的用例类似于unittest.TestCase._cleanups-测试完成后将调用的方法堆栈。该框架必须能够运行以下代码:
# obj is a child instance of the A class
obj.append(obj.child_method) …Run Code Online (Sandbox Code Playgroud)