sjs7007 / S3Lab

Code for Deep Cloud back end.
http://deepc05.acis.ufl.edu:8080/
0 stars 0 forks source link

Integrate citrus script. #8

Open sjs7007 opened 8 years ago

sjs7007 commented 8 years ago

For basic integration, using sockets and a sample subset in data, just do

head -n 30 1-20.csv > sample.csv

to get a sample dataset.

Run it using sockets and python with the -u parameter which means stdout will not be buffered and hence there is no need to flush it again and again.

Server side code :

var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var count = 0;

server.listen(9090);

app.get('/', function (req, res) {
  res.sendFile(__dirname + '/testSocket3.html');
});

io.on('connection', function (socket) {
    console.log("here 2");
    var spawn = require('child_process').spawn;
    var py = spawn('python',['-u','keras_code2.py'],{cwd:'citrus'});

    py.stdout.on('data',function(pyStdout) {
        console.log("godyt data count : "+count++)
        console.log(pyStdout.toString());
        socket.emit('pythonSocket',pyStdout.toString());
    });

    //to stop process 
    socket.on("pause",function() {
        console.log("pausing pid : "+py.pid);
        socket.emit("pythonSocket","pausing pid : "+py.pid);
        process.kill(py.pid,"SIGTSTP");
    });

    //to resume process
    socket.on("continue",function() {
        console.log("resuming pid : "+py.pid);
        socket.emit("pythonSocket","resuming pid : "+py.pid);
        process.kill(py.pid,"SIGCONT");
    }); 

});

Client side html code :

<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.js"></script>
<script>
  document.write("test");
  var socket = io.connect('http://deepc05.acis.ufl.edu:9090');
  socket.on('pythonSocket',function( data ) {
    document.write(data+"<br>");
  });
  socket.emit('pause');
  socket.emit('continue');
</script>
</html>
sjs7007 commented 8 years ago

Next working on using json to improve output format