Skip to content

Commit 4558137

Browse files
committed
removed some diagnostics, random fixes
1 parent b7f90b8 commit 4558137

File tree

6 files changed

+57
-50
lines changed

6 files changed

+57
-50
lines changed

src/info/sansgills/mode/python/Communicator.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package info.sansgills.mode.python;
22

3-
import java.awt.Point;
43
import java.io.BufferedReader;
54
import java.io.InputStream;
65
import java.io.InputStreamReader;
76
import java.io.PrintWriter;
87

8+
import java.util.Timer;
9+
910
import processing.app.exec.StreamRedirectThread;
10-
import processing.core.PApplet;
11+
1112

1213
/**
1314
*
@@ -25,6 +26,8 @@ public class Communicator {
2526

2627
private PrintWriter toSketch;
2728

29+
private Timer sketchHanging; //TODO
30+
2831
public Communicator (Process sketchProcess, PythonRunner runner){
2932
this.sketchProcess = sketchProcess;
3033
this.runner = runner;
@@ -46,9 +49,6 @@ public void destroy(){
4649
toSketch = null;
4750
}
4851

49-
50-
// communication methods
51-
5252
/*
5353
* Tell sketch to close
5454
*/
@@ -83,30 +83,23 @@ public MessageReceiverThread(InputStream messageStream, PythonRunner runner){
8383
this.runner = runner;
8484
this.running = true;
8585
}
86-
86+
8787
public void run() {
8888
try {
8989
String currentLine;
90-
9190
// continually read messages
92-
while ((currentLine = messageReader.readLine()) != null) {
93-
if(!running){
94-
System.out.println("Messenger thread no longer running");
95-
return;
96-
}
91+
while ((currentLine = messageReader.readLine()) != null && running) {
9792
if (currentLine.indexOf("__STOPPED__") != -1) {
98-
// sketch telling us it stopped
9993
runner.parallelStopped();
100-
System.out.println("Stopped recieved.");
101-
return;
102-
}else if(currentLine.indexOf("__STARTED__") != -1){
94+
} else if (currentLine.indexOf("__STARTED__") != -1) {
10395
runner.parallelStarted();
104-
System.out.println("Started recieved.");
105-
} else{
96+
} else {
10697
System.err.println(currentLine);
10798
}
10899
}
109-
} catch (Exception e) {e.printStackTrace();}
100+
} catch (Exception e) {
101+
e.printStackTrace();
102+
}
110103
}
111104
}
112105
}

src/info/sansgills/mode/python/PythonBuild.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private String preprocess(StringBuilder program){
101101
return "def setup():\n\tpass\n\n"; //empty sketch; TODO fix hack
102102
}
103103
try{
104+
program.append("\n"); //to be safe
104105
PyPdeLexer lexer = new PyPdeLexer(new ANTLRInputStream(program.toString()));
105106
CommonTokenStream tokens = new CommonTokenStream(lexer);
106107
PyPdeParser parser = new PyPdeParser(tokens);

src/info/sansgills/mode/python/PythonRunner.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public void run() {
5252
*/
5353
public void launch(PythonBuild build, boolean present) {
5454
needsReboot = build.usesOpenGL;
55-
System.out.println("we need to reboot: "+needsReboot);
5655
ensureParallel();
5756
String[] a = buildSketchArgs(build, present);
58-
System.out.println(a);
5957
communicator.sendSketch(a);
6058
}
6159

@@ -74,7 +72,6 @@ public void internalClose() {
7472
* Sketch process died; get ready to reboot it
7573
*/
7674
private void prepareReboot(){
77-
System.out.println("rebooting");
7875
if(!dying){
7976
sketchProcess = null;
8077
communicator.destroy();
@@ -86,7 +83,6 @@ private void prepareReboot(){
8683
* Force sketch process to restart
8784
*/
8885
public void forceReboot(){
89-
System.out.println("Forcing reboot.");
9086
if(sketchProcess != null) sketchProcess.destroy();
9187
}
9288

@@ -102,7 +98,7 @@ private void ensureParallel(){
10298
public void run(){
10399
try{
104100
int result = sketchProcess.waitFor();
105-
System.out.println("parallel process killed");
101+
System.err.println("parallel process died with code "+result);
106102
prepareReboot();
107103
}catch(InterruptedException e){
108104
System.err.println("someone interrupted the deathwatch thread");
@@ -121,9 +117,8 @@ public void parallelStopped() {
121117
}
122118
}
123119
public void parallelStarted(){
124-
125120
}
126-
121+
127122
/*
128123
* Command to start the companion process
129124
*/

src/info/sansgills/mode/python/preproc/PyPdeConverter.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PyPdeConverter extends PyPdeBaseListener {
2020
"width","height","displayWidth","displayHeight","focused","frameCount"
2121
}));
2222
static final Set<String> wonkyVars = new HashSet<String>(Arrays.asList(new String[]{
23-
"mousePressed", "keyPressed", "frameRate"
23+
"mousePressed", "keyPressed"
2424
}));
2525

2626
TokenStream tokens;
@@ -81,6 +81,26 @@ public void enterAtom(PyPdeParser.AtomContext ctx){
8181
//can't do __applet__.mousePressed Jython thinks that refers to the function
8282
rewriter.insertBefore(id.IDENTIFIER().getSymbol(), "get");
8383
rewriter.insertAfter(id.IDENTIFIER().getSymbol(), "()");
84+
}else if(text.equals("frameRate")){
85+
//special handling; if it's a call, use it as frameRate()
86+
//if it's not, use it as a call to getframeRate()
87+
boolean isCall;
88+
for(int i = id.start.getTokenIndex(); ; i++){
89+
int type = tokens.get(i+1).getType();
90+
if(type == PyPdeParser.LPAREN){
91+
isCall = true;
92+
break;
93+
}else if(type == PyPdeParser.WS){
94+
continue;
95+
}else{
96+
isCall = false;
97+
break;
98+
}
99+
}
100+
if(!isCall){
101+
rewriter.insertBefore(id.IDENTIFIER().getSymbol(), "get");
102+
rewriter.insertAfter(id.IDENTIFIER().getSymbol(), "()");
103+
}
84104
}
85105
}
86106
}
@@ -89,9 +109,7 @@ public void enterAtom(PyPdeParser.AtomContext ctx){
89109
@Override
90110
public void enterCall(PyPdeParser.CallContext ctx) {
91111
if (ctx.primary() instanceof PyPdeParser.PrimaryAtomContext) {
92-
System.out.println("found a funcall");
93112
if (ctx.primary().getText().equals("size")) {
94-
System.out.println("found size");
95113
if(getArgs.matcher(ctx.getText()).find()){
96114
usesOpenGL = true;
97115
}

src/info/sansgills/mode/python/wrapper/ProcessingJythonWrapper.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package info.sansgills.mode.python.wrapper;
22

3-
import info.sansgills.mode.python.PythonEditor;
4-
53
import java.awt.Color;
64
import java.awt.Dimension;
75
import java.awt.Frame;
@@ -76,7 +74,16 @@ public class ProcessingJythonWrapper {
7674
* in which case we get ready to connect and pass messages, or it's not, in
7775
* which case this is a one-shot job and nobody's listening
7876
*/
79-
public static void main(String[] args) {
77+
public static void main(String[] args) {
78+
//kill ourselves if something bad happens
79+
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
80+
public void uncaughtException(Thread t, Throwable e){
81+
e.printStackTrace();
82+
System.exit(0);
83+
}
84+
});
85+
86+
8087
// the PDE will have this as the only arument if we're running paired
8188
parallel = args[0].indexOf("--parallel") != -1;
8289

@@ -109,27 +116,26 @@ public static void prepare() {
109116
sys = Py.getSystemState(); // python 'sys' variable
110117

111118
PySystemState.add_package("info.sansgills.mode.python.wrapper");
112-
//PySystemState.add_package("processing.core");
113-
//PySystemState.add_package("processing.opengl");
114-
//PySystemState.add_package("processing.event");
115-
//PySystemState.add_package("processing.data");
116119

117120
ready = true;
118121
}
119122

120-
public static void sendStarted(){
121-
System.err.println("__STARTED__");
122-
System.out.println("started sent");
123+
public static void sendStarted() {
124+
if (parallel) {
125+
System.err.println("__STARTED__");
126+
System.err.flush();
127+
}
123128
}
124129
public static void sendStopped(){
125-
System.err.println("__STOPPED__");
126-
System.out.println("stopped sent");
130+
if (parallel) {
131+
System.err.println("__STOPPED__");
132+
System.err.flush();
133+
}
127134
}
128135

129-
130136
public static void startSketch(String[] args){
131137
if(applet != null){
132-
applet.exit();
138+
terminateSketch();
133139

134140
while(applet != null){
135141
try{
@@ -141,7 +147,7 @@ public static void startSketch(String[] args){
141147
while (!ready) {
142148
try {
143149
Thread.sleep(50);
144-
} catch (Exception e){}
150+
} catch (InterruptedException e){}
145151
}
146152

147153
//applet is now null
@@ -580,5 +586,4 @@ public void run() {
580586
}
581587
}
582588
}
583-
584589
}

src/info/sansgills/mode/python/wrapper/PythonPApplet.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void setup(){
9393
if(e.getCause() instanceof RendererChangeException){
9494
// Processing uses this to signal a change in renderer
9595
// chuck it up the stack
96-
System.out.println("renderer changing");
9796
throw (RendererChangeException) e.getCause();
9897
}else{
9998
throw e;
@@ -169,14 +168,10 @@ public float getframeRate(){
169168
@Override
170169
public void dispose(){
171170
if (!disposed) {
172-
System.out.println("disposing sketch");
173171
disposed = true;
174172
super.dispose();
175173
frame.dispose();
176-
177174
ProcessingJythonWrapper.sketchDisposed();
178-
179-
System.out.println("done disposing");
180175
}
181176
}
182177

0 commit comments

Comments
 (0)