我正在构建一个Java框架,它将监听事件,然后在Jython中处理它们.不同的事件类型将被发送到不同的脚本.
由于在调用PythonInterpreter.exec()时jython需要相当长的时间来编译脚本,因此我必须预编译脚本.我是按照以下方式做的:
// initialize the script as string (would load it from file in final version)
String script = "print 'foo'";
// get the compiled code object
PyCode compiled = org.python.core.__builtin__.compile( script, "<>", "exec" );
Run Code Online (Sandbox Code Playgroud)
PyCode编译对象将被推送到存储库并在事件进入时使用
PythonInterpreter pi = new PythonInterpreter();
pi.set( "variable_1", "value_1");
pi.set( "variable_x", "value_x");
pi.exec( compiled );
Run Code Online (Sandbox Code Playgroud)
现在,对于我的难题 - 可能会发生某些类型的多个事件同时发生 - 因此同时运行多个脚本实例.
几乎所有脚本都可能保持短暂 - 最多100行,没有循环.数字和频率是完全随机的(用户生成的事件),每个事件类型可以是每秒0到大约200.
最好的方法是什么?我正在寻找一些可能性:
2号和3号的组合可能是最好的 - 创建动态池大小?
那么,有什么想法吗?;)
I'm doing a simple grep for lines starting with some patteren like:
grep -E "^AAA" myfile > newfile
Run Code Online (Sandbox Code Playgroud)
我还想(同时)将那些不匹配的行重定向到另一个文件。
我知道可以简单地做两次并在第二次尝试中使用-v,但是文件(相对)很大,只读取一次会节省一些非常宝贵的时间......
我正在考虑将不匹配重定向到 stderr 的一些事情,例如:
grep -E -magic_switch "^AAA" myfile > newfile 2> newfile.nonmatch
Run Code Online (Sandbox Code Playgroud)
这个技巧是否可以用grep还是我应该只编码它?
(可能有额外的价值 - 我在 bash 脚本中编码)