在 Akka 2.6 之前,或者使用经典 Actors,可以编写 Akka 扩展以访问 Akka 无类型 actor 中 Spring 的 @Inject 注释。
一个例子是:https : //github.com/typesafehub/activator-akka-java-spring/blob/master/src/main/java/sample/SpringExtension.java
但是,这不适用于新的 Akka Typed 演员。
Akka 的文档没有展示如何制作这样的扩展(但它确实展示了如何制作简单的扩展:https : //doc.akka.io/docs/akka/current/typed/extending.html#building-an-extension) .
到目前为止,我写了这个扩展的开头,但我不知道如何将Spring的ApplicationContext与actor系统联系起来:
import org.springframework.context.ApplicationContext;
import akka.actor.typed.ActorSystem;
import akka.actor.typed.Extension;
import akka.actor.typed.ExtensionId;
public class SpringExtension implements Extension {
private volatile ApplicationContext applicationContext;
private SpringExtension(final ActorSystem<?> system) {
// TODO: What do you put here?
}
void initialize(final ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public static class Id extends ExtensionId<SpringExtension> {
private static …Run Code Online (Sandbox Code Playgroud) 即使在阅读了有关引用所有权和借用的章节之后,我仍然无法理解以下代码中的某些内容,这有效地阻止了我从clap::App!
extern crate clap;
use clap::App;
fn main() {
let mut app =
App::new("name me").args_from_usage("<input_file> 'Sets the input file to use'");
let matches = app.get_matches();
app.print_help();
println!(
"Using input file: {}",
matches.value_of("input_file").unwrap()
);
}
Run Code Online (Sandbox Code Playgroud)
编译此代码会导致:
extern crate clap;
use clap::App;
fn main() {
let mut app =
App::new("name me").args_from_usage("<input_file> 'Sets the input file to use'");
let matches = app.get_matches();
app.print_help();
println!(
"Using input file: {}",
matches.value_of("input_file").unwrap()
);
}
Run Code Online (Sandbox Code Playgroud)
app.get_matches()要求借用所有权,那么app一定是mut。一旦函数返回,所有权会去哪里?app仍然拥有该对象的所有权,但编译器有不同的意见。 …我一直在尝试编写一个异步版本map我一直在尝试用 Python
为此,我使用带有生产者/消费者的队列。
起初它似乎运行良好,但无一例外。
特别是,如果我使用queue.join(),它在没有异常时运行良好,但在异常情况下会阻塞。如果我使用gather(*tasks),它在出现异常时效果很好,但如果没有则阻塞。
所以有时它只会完成,我只是不明白为什么。
这是我实现的代码:
import asyncio
from asyncio import Queue
from typing import Iterable, Callable, TypeVar
Input = TypeVar("Input")
Output = TypeVar("Output")
STOP = object()
def parallel_map(func: Callable[[Input], Output], iterable: Iterable[Input]) -> Iterable[Output]:
"""
Parallel version of `map`, backed by asyncio.
Only suitable to do IO in parallel (not for CPU intensive tasks, otherwise it will block).
"""
number_of_parallel_calls = 9
async def worker(input_queue: Queue, output_queue: Queue) -> None:
while True: …Run Code Online (Sandbox Code Playgroud) 我有一个字符串列表(像这样的单词),当我解析文本时,我需要检查一个单词是否属于我当前列表中的单词组.
但是,我的输入非常大(大约6亿行),并且根据Python文档检查元素是否属于列表是O(n)操作.
我的代码是这样的:
words_in_line = []
for word in line:
if word in my_list:
words_in_line.append(word)
Run Code Online (Sandbox Code Playgroud)
由于花费了太多时间(实际上是几天),我想改进大部分时间都要花费的那部分.我看看Python集合,更准确地说,看看deque.但是,只允许O(1)操作时间访问列表的头部和尾部,而不是在中间.
有人知道如何以更好的方式做到这一点吗?
我有一个名为repo1的存储库,它是我的基础.
我把它克隆到repo2.
我有另一个存储库包含一些不相关的文件和历史记录,名为other_repo.
多亏了hg convert,我可以将other_repo的子集导入repo2,同时保留文件的历史记录:
hg convert --filemap my_file other_repo temp_repo
cd repo2
hg pull -f temp_repo
Run Code Online (Sandbox Code Playgroud)
这是完美无瑕的.
但是,现在,如果我将repo2中的更改捆绑在一起,并尝试在repo1中解包它们,我会收到以下错误:
adding changesets
transaction abort!
rollback completed
abort: 00changelog.i@82dc9cd3be46: unknown parent!
Run Code Online (Sandbox Code Playgroud)
嗯,这很正常.新的父级来自other_repo,现在需要它.请注意,来自repo2的hg pull in repo1工作正常.
在这种情况下(当存储库的历史很好,hg verify没有抱怨,我没有剥离任何东西),有没有办法强制解开捆绑行动?