Combining Synchronous Python w/ NodeJS









up vote
0
down vote

favorite












I have a node script that looks like this:



// Preset Modules...
const fs = require("fs-extra");
const path = require("path");
const join = path;
const axios = require("axios");

// Global/Multi modules...
const today = require("./keys/globals");
const logger = require("./logger");

// Sequence modules...
const downloader = require("./downloader");
const settingScraper = require("./settings");
const treeMaker = require("./treeMaker");
/****/ const pythonWriter = require("./pythonWriter"); /****/
const fbDaemon = require("./firebase");
const zipper = require("./zipper");
const mailer = require("./mailer");
const success, failure = require("./results");

logger.write(`nStarting download for: $today, at $Date.now()`);

axios.get(`http://federalregister.gov/api/v1/public-inspection-documents.json?conditions%5Bavailable_on%5D=$today`)
.then(downloader)
.then(settingScraper)
.then(treeMaker)
/****/ .then(pythonWriter) /****/
.then(fbDaemon) // Should pass down array structure, like in config file.
.then(zipper)
.then(mailer)
.then(success)
.catch(failure);


The function downloads a number of files from an API online, and the pythonWriter is a separate module. Within that module I would like to trigger a python script, which would "pause" or execute synchronously, before they pythonWriter returned a promise. The promise wouldn't have to contain any data.



Look something like this:



const util = require("util");
const spawn = require("child_process").spawn;

const pythonWriter = () =>
const process = spawn("python", ["./script.py"]);


module.exports = pythonWriter;


How can I spawn or create a sub-process that executes synchronously before the rest of my Javascript code? Or, if that's not possible, return a promise-like object that would then trigger a separate then-block?



Thanks for your help.










share|improve this question

















  • 1




    Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
    – jfriend00
    Nov 10 at 1:16











  • Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
    – Harry Cramer
    Nov 13 at 0:50














up vote
0
down vote

favorite












I have a node script that looks like this:



// Preset Modules...
const fs = require("fs-extra");
const path = require("path");
const join = path;
const axios = require("axios");

// Global/Multi modules...
const today = require("./keys/globals");
const logger = require("./logger");

// Sequence modules...
const downloader = require("./downloader");
const settingScraper = require("./settings");
const treeMaker = require("./treeMaker");
/****/ const pythonWriter = require("./pythonWriter"); /****/
const fbDaemon = require("./firebase");
const zipper = require("./zipper");
const mailer = require("./mailer");
const success, failure = require("./results");

logger.write(`nStarting download for: $today, at $Date.now()`);

axios.get(`http://federalregister.gov/api/v1/public-inspection-documents.json?conditions%5Bavailable_on%5D=$today`)
.then(downloader)
.then(settingScraper)
.then(treeMaker)
/****/ .then(pythonWriter) /****/
.then(fbDaemon) // Should pass down array structure, like in config file.
.then(zipper)
.then(mailer)
.then(success)
.catch(failure);


The function downloads a number of files from an API online, and the pythonWriter is a separate module. Within that module I would like to trigger a python script, which would "pause" or execute synchronously, before they pythonWriter returned a promise. The promise wouldn't have to contain any data.



Look something like this:



const util = require("util");
const spawn = require("child_process").spawn;

const pythonWriter = () =>
const process = spawn("python", ["./script.py"]);


module.exports = pythonWriter;


How can I spawn or create a sub-process that executes synchronously before the rest of my Javascript code? Or, if that's not possible, return a promise-like object that would then trigger a separate then-block?



Thanks for your help.










share|improve this question

















  • 1




    Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
    – jfriend00
    Nov 10 at 1:16











  • Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
    – Harry Cramer
    Nov 13 at 0:50












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a node script that looks like this:



// Preset Modules...
const fs = require("fs-extra");
const path = require("path");
const join = path;
const axios = require("axios");

// Global/Multi modules...
const today = require("./keys/globals");
const logger = require("./logger");

// Sequence modules...
const downloader = require("./downloader");
const settingScraper = require("./settings");
const treeMaker = require("./treeMaker");
/****/ const pythonWriter = require("./pythonWriter"); /****/
const fbDaemon = require("./firebase");
const zipper = require("./zipper");
const mailer = require("./mailer");
const success, failure = require("./results");

logger.write(`nStarting download for: $today, at $Date.now()`);

axios.get(`http://federalregister.gov/api/v1/public-inspection-documents.json?conditions%5Bavailable_on%5D=$today`)
.then(downloader)
.then(settingScraper)
.then(treeMaker)
/****/ .then(pythonWriter) /****/
.then(fbDaemon) // Should pass down array structure, like in config file.
.then(zipper)
.then(mailer)
.then(success)
.catch(failure);


The function downloads a number of files from an API online, and the pythonWriter is a separate module. Within that module I would like to trigger a python script, which would "pause" or execute synchronously, before they pythonWriter returned a promise. The promise wouldn't have to contain any data.



Look something like this:



const util = require("util");
const spawn = require("child_process").spawn;

const pythonWriter = () =>
const process = spawn("python", ["./script.py"]);


module.exports = pythonWriter;


How can I spawn or create a sub-process that executes synchronously before the rest of my Javascript code? Or, if that's not possible, return a promise-like object that would then trigger a separate then-block?



Thanks for your help.










share|improve this question













I have a node script that looks like this:



// Preset Modules...
const fs = require("fs-extra");
const path = require("path");
const join = path;
const axios = require("axios");

// Global/Multi modules...
const today = require("./keys/globals");
const logger = require("./logger");

// Sequence modules...
const downloader = require("./downloader");
const settingScraper = require("./settings");
const treeMaker = require("./treeMaker");
/****/ const pythonWriter = require("./pythonWriter"); /****/
const fbDaemon = require("./firebase");
const zipper = require("./zipper");
const mailer = require("./mailer");
const success, failure = require("./results");

logger.write(`nStarting download for: $today, at $Date.now()`);

axios.get(`http://federalregister.gov/api/v1/public-inspection-documents.json?conditions%5Bavailable_on%5D=$today`)
.then(downloader)
.then(settingScraper)
.then(treeMaker)
/****/ .then(pythonWriter) /****/
.then(fbDaemon) // Should pass down array structure, like in config file.
.then(zipper)
.then(mailer)
.then(success)
.catch(failure);


The function downloads a number of files from an API online, and the pythonWriter is a separate module. Within that module I would like to trigger a python script, which would "pause" or execute synchronously, before they pythonWriter returned a promise. The promise wouldn't have to contain any data.



Look something like this:



const util = require("util");
const spawn = require("child_process").spawn;

const pythonWriter = () =>
const process = spawn("python", ["./script.py"]);


module.exports = pythonWriter;


How can I spawn or create a sub-process that executes synchronously before the rest of my Javascript code? Or, if that's not possible, return a promise-like object that would then trigger a separate then-block?



Thanks for your help.







python node.js asynchronous process promise






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 23:42









Harry Cramer

337214




337214







  • 1




    Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
    – jfriend00
    Nov 10 at 1:16











  • Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
    – Harry Cramer
    Nov 13 at 0:50












  • 1




    Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
    – jfriend00
    Nov 10 at 1:16











  • Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
    – Harry Cramer
    Nov 13 at 0:50







1




1




Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
– jfriend00
Nov 10 at 1:16





Have you looked at the child_process documentation? You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() to see when they are done. It's not clear what you're asking that is fully covered in the child_process doc.
– jfriend00
Nov 10 at 1:16













Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
– Harry Cramer
Nov 13 at 0:50




Thank you. This is what I needed, just looked into spawn a bit more and then on exit, performed the rest of the code.
– Harry Cramer
Nov 13 at 0:50












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Have you looked at the child_process documentation?



You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() or .spawn() to see when they are done.



It seems that what you're asking is already covered in the child_process doc.



Here's an example using .spawn() taken from the doc:



const spawn = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) =>
console.log(`stdout: $data`);
);

ls.stderr.on('data', (data) =>
console.log(`stderr: $data`);
);

ls.on('close', (code) =>
console.log(`child process exited with code $code`);
);


You could listen for the close event to see when it's done.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234661%2fcombining-synchronous-python-w-nodejs%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Have you looked at the child_process documentation?



    You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() or .spawn() to see when they are done.



    It seems that what you're asking is already covered in the child_process doc.



    Here's an example using .spawn() taken from the doc:



    const spawn = require('child_process');
    const ls = spawn('ls', ['-lh', '/usr']);

    ls.stdout.on('data', (data) =>
    console.log(`stdout: $data`);
    );

    ls.stderr.on('data', (data) =>
    console.log(`stderr: $data`);
    );

    ls.on('close', (code) =>
    console.log(`child process exited with code $code`);
    );


    You could listen for the close event to see when it's done.






    share|improve this answer
























      up vote
      1
      down vote



      accepted










      Have you looked at the child_process documentation?



      You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() or .spawn() to see when they are done.



      It seems that what you're asking is already covered in the child_process doc.



      Here's an example using .spawn() taken from the doc:



      const spawn = require('child_process');
      const ls = spawn('ls', ['-lh', '/usr']);

      ls.stdout.on('data', (data) =>
      console.log(`stdout: $data`);
      );

      ls.stderr.on('data', (data) =>
      console.log(`stderr: $data`);
      );

      ls.on('close', (code) =>
      console.log(`child process exited with code $code`);
      );


      You could listen for the close event to see when it's done.






      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Have you looked at the child_process documentation?



        You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() or .spawn() to see when they are done.



        It seems that what you're asking is already covered in the child_process doc.



        Here's an example using .spawn() taken from the doc:



        const spawn = require('child_process');
        const ls = spawn('ls', ['-lh', '/usr']);

        ls.stdout.on('data', (data) =>
        console.log(`stdout: $data`);
        );

        ls.stderr.on('data', (data) =>
        console.log(`stderr: $data`);
        );

        ls.on('close', (code) =>
        console.log(`child process exited with code $code`);
        );


        You could listen for the close event to see when it's done.






        share|improve this answer












        Have you looked at the child_process documentation?



        You can either use spawnSync() or you can watch for events on the childProcess object returned by spawn to know when its done or you can use the callback function with .exec() or .execFile() or .spawn() to see when they are done.



        It seems that what you're asking is already covered in the child_process doc.



        Here's an example using .spawn() taken from the doc:



        const spawn = require('child_process');
        const ls = spawn('ls', ['-lh', '/usr']);

        ls.stdout.on('data', (data) =>
        console.log(`stdout: $data`);
        );

        ls.stderr.on('data', (data) =>
        console.log(`stderr: $data`);
        );

        ls.on('close', (code) =>
        console.log(`child process exited with code $code`);
        );


        You could listen for the close event to see when it's done.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 1:12









        jfriend00

        423k51535583




        423k51535583



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234661%2fcombining-synchronous-python-w-nodejs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus