我有一个Future,我想找出它的状态.我想到的是一个代码,如:
try {
// Is that a good idea? Counting on exceptions looks weird.
future.get(0, TimeUnit.MICROSECONDS);
this.status = DONE;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
} catch (ExecutionException e) {
this.status = FAILED;
} catch (TimeoutException e) {
this.status = RUNNING;
} catch (CancellationException e) {
this.status = CANCELED;
}
Run Code Online (Sandbox Code Playgroud)
看起来FutureTask会尝试持有一个锁,如果它可以获得锁将检查Future的状态.所以这似乎是一个好主意.
我在这里缺少陷阱吗?
我想打电话Thread.sleep,并传播InterruptException它确实它被扔了.
想象的语法:
Interruptibles.sleep(1000);
Run Code Online (Sandbox Code Playgroud)
这相当于
try {
Thread.sleep(1000);
} catch (InterruptException e) {
throw Throwables.propagate(e);
}
Run Code Online (Sandbox Code Playgroud)
在公共库(番石榴,apache公共等)中是否有类似的功能.
什么是创建独立pip包的最佳方法,它可以在安装了裸包的任何机器上运行?
说,我想打包pelican,以便它可以在所有安装了python的计算机上运行(假设所有依赖项都是纯python).