我的理解是,如果输入了try,则必须*始终*执行finally子句.
import random
from multiprocessing import Pool
from time import sleep
def Process(x):
try:
print x
sleep(random.random())
raise Exception('Exception: ' + x)
finally:
print 'Finally: ' + x
Pool(3).map(Process, ['1','2','3'])
Run Code Online (Sandbox Code Playgroud)
预期的输出是对于每个由第8行单独打印的x,必须出现'Finally x'.
示例输出:
$ python bug.py
1
2
3
Finally: 2
Traceback (most recent call last):
File "bug.py", line 14, in <module>
Pool(3).map(Process, ['1','2','3'])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 225, in map
return self.map_async(func, iterable, chunksize).get()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 522, in get
raise self._value
Exception: Exception: 2
Run Code Online (Sandbox Code Playgroud)
似乎终止一个进程的异常终止了父进程和兄弟进程,即使在其他进程中还有其他工作 …
如果readme Cargo.toml设置了键,doc.rs 会在 crate 的索引页面上呈现 README。在cargo doc本地运行时有没有办法模拟这一点?
如果我添加:
#![doc = r###"contents
of
README.md
here
"###]
Run Code Online (Sandbox Code Playgroud)
作为字面意思,我得到了我正在寻找的行为,但是内联整个 README.md 的副本对于进行更新非常不方便。
我试过:
#![doc = include!("README.md")]
Run Code Online (Sandbox Code Playgroud)
但这给出了一个错误:
error: unexpected token: `include`
--> src/lib.rs:3:10
|
3 | #![doc = include!("README.md")]
| ^^^^^^^
Run Code Online (Sandbox Code Playgroud) 如何NSAttributedString使用ranged属性初始化?
就目前而言,我只能弄清楚如何在初始化后添加一个ranged属性,这显然不适用于不可变NSAttributedString实例.
如果我有NSMutableAttributedString,我可以打电话:
[str addAttribute:NSLinkAttributeName value:url range:range];
Run Code Online (Sandbox Code Playgroud)
如果我有NSAttributedString,我可以构建它:
[[NSAttributedString alloc] initWithString:str attributes:@{NSLinkAttributeName: url}];
Run Code Online (Sandbox Code Playgroud)
但我找不到将范围放入attributesDict的方法.
谢谢,