Skip to content

Commit

Permalink
BugFix:
Browse files Browse the repository at this point in the history
1.

NewAdd:
1.
  • Loading branch information
yishenggudou committed Dec 18, 2018
1 parent a69088c commit ad923ab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
import org.python.core.Py;
import org.python.core.PySystemState;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

/**
* @author timger
*/
public class BlitzcrankEngine {


private static final BlitzcrankEngine instance = new BlitzcrankEngine();

private Set<String> paths = new HashSet<>();

private BlitzcrankEngine() {
}

public static BlitzcrankEngine getInstance() {
return instance;
}

public void addPath(String path) {
this.paths.add(path);
}

private PySystemState defaultPySystemState;

public PySystemState getPySystemState() {
Expand All @@ -34,18 +43,33 @@ public PySystemState getPySystemState() {
properties.put("python.import.site", "false");
PySystemState.initialize(sysProps, properties);
PySystemState pySystemState = Py.getSystemState();
// System.out.println(pySystemState.modules);
// System.out.println(pySystemState.getBuiltins());
pySystemState.path.add("target/classes/Lib");
pySystemState.path.add("target/jython-plugins-tmp/Lib");
pySystemState.path.add("classes/Lib");
String jlib = System.getProperty("jlib");
if (jlib != null) {
pySystemState.path.add(jlib);
}
System.out.println(pySystemState.path);
try {
String current = new java.io.File(".").getCanonicalPath();
System.out.println(current);
} catch (Throwable throwable) {

}
this.defaultPySystemState = pySystemState;
return pySystemState;
}
}


public IRunnerType get(String moduleName, String className) {
PySystemState pySystemState = getPySystemState();
// System.out.println(pySystemState.path);
for (String path : this.paths) {
if (pySystemState.path.indexOf(path) < 0) {
pySystemState.path.add(path);
}
}
JythonObjectFactory factory = new JythonObjectFactory(
pySystemState,
IRunnerType.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# yishenggudou@gmail.com
# @timger http://weibo.com/zhanghaibo

from com.github.yishenggudou.blitzcrank.common import IRunnerType


Expand All @@ -14,7 +15,12 @@ def initialize(self, params, settings):
pass

def run(self):
#print "test run obj"
# print "test run obj"
import urllib2
req = urllib2.Request("http://mirrors.aliyun.com/pypi/")
response = urllib2.urlopen(req)
the_page = response.read()
response.close()
return ""

def getStatus(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ public class BlitzcrankEngineTest {
public void get() {
Integer step = 0;
Long start = System.currentTimeMillis();
while (step < 1000) {
Integer times = 3000;
while (step < times) {
BlitzcrankEngine blitzcrankEngine = BlitzcrankEngine.getInstance();
blitzcrankEngine.addPath("/data/github/blitzcrank/target/jython-plugins-tmp/Lib");
IRunnerType iRunnerType = blitzcrankEngine.get("jwrapper.BaskRunner", "BaskRunner");
iRunnerType.run();
step += 1;
}
Long end = System.currentTimeMillis();
System.out.println(end - start);
Long token = end - start;
System.out.println(token);
System.out.println(String.format("%f ms", Float.valueOf(token) / times));
}
}

0 comments on commit ad923ab

Please sign in to comment.