Julia invoke script on existing REPL from command line










1















I want to run a Julia script from window command line, but it seems everytime I run > Julia code.jl, a new instance of Julia is created and the initiation time (package loading, compiling?) is quite long.



Is there a way for me to skip this initiation time by running the script on the current REPL/Julia instance? (which usually saves me 50% of running time).



I am using Julia 1.0.



Thank you,










share|improve this question


























    1















    I want to run a Julia script from window command line, but it seems everytime I run > Julia code.jl, a new instance of Julia is created and the initiation time (package loading, compiling?) is quite long.



    Is there a way for me to skip this initiation time by running the script on the current REPL/Julia instance? (which usually saves me 50% of running time).



    I am using Julia 1.0.



    Thank you,










    share|improve this question
























      1












      1








      1








      I want to run a Julia script from window command line, but it seems everytime I run > Julia code.jl, a new instance of Julia is created and the initiation time (package loading, compiling?) is quite long.



      Is there a way for me to skip this initiation time by running the script on the current REPL/Julia instance? (which usually saves me 50% of running time).



      I am using Julia 1.0.



      Thank you,










      share|improve this question














      I want to run a Julia script from window command line, but it seems everytime I run > Julia code.jl, a new instance of Julia is created and the initiation time (package loading, compiling?) is quite long.



      Is there a way for me to skip this initiation time by running the script on the current REPL/Julia instance? (which usually saves me 50% of running time).



      I am using Julia 1.0.



      Thank you,







      cmd julia read-eval-print-loop






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 16:08









      Huy TranHuy Tran

      112




      112






















          2 Answers
          2






          active

          oldest

          votes


















          1














          There are several possible solutions. All of them involve different ways of sending commands to a running Julia session. The first few that come to my mind are:



          • use sockets as explained in https://docs.julialang.org/en/v1/manual/networking-and-streams/#A-simple-TCP-example-1

          • set up a HTTP server e.g. using https://github.com/JuliaWeb/HTTP.jl

          • use named pipes, as explained in Named pipe does not wait until completion in bash

          • communicate e.g. through the file system (e.g. make Julia scan some folder for .jl files and if it finds them there they get executed and moved to another folder or deleted) - this is probably simplest to implement correctly

          In all the solutions you can send the command to Julia by executing some shell command.



          No matter which approach you prefer the key challenge is sanitizing the code to handle errors properly (i.e. a situation when you sent some command to the Julia session and it crashes or when you send requests faster than Julia is able to handle them). This is especially important if you want the Julia server to be detached from the terminal.



          As a side note: when using the Distributed module from stdlib in Julia for multiprocessing you actually do a very similar thing (but the communication is Julia to Julia) so you can also have a look how this module is implemented to get the feeling how it can be done.






          share|improve this answer























          • Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

            – Huy Tran
            Nov 15 '18 at 22:39











          • Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

            – Bogumił Kamiński
            Nov 15 '18 at 22:42


















          0














          You can use include:



          julia> include("code.jl")





          share|improve this answer























          • Hi, it should be from terminal (cmd), not from the current running julia REPL.

            – Huy Tran
            Nov 15 '18 at 16:50










          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',
          autoActivateHeartbeat: false,
          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%2f53323489%2fjulia-invoke-script-on-existing-repl-from-command-line%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There are several possible solutions. All of them involve different ways of sending commands to a running Julia session. The first few that come to my mind are:



          • use sockets as explained in https://docs.julialang.org/en/v1/manual/networking-and-streams/#A-simple-TCP-example-1

          • set up a HTTP server e.g. using https://github.com/JuliaWeb/HTTP.jl

          • use named pipes, as explained in Named pipe does not wait until completion in bash

          • communicate e.g. through the file system (e.g. make Julia scan some folder for .jl files and if it finds them there they get executed and moved to another folder or deleted) - this is probably simplest to implement correctly

          In all the solutions you can send the command to Julia by executing some shell command.



          No matter which approach you prefer the key challenge is sanitizing the code to handle errors properly (i.e. a situation when you sent some command to the Julia session and it crashes or when you send requests faster than Julia is able to handle them). This is especially important if you want the Julia server to be detached from the terminal.



          As a side note: when using the Distributed module from stdlib in Julia for multiprocessing you actually do a very similar thing (but the communication is Julia to Julia) so you can also have a look how this module is implemented to get the feeling how it can be done.






          share|improve this answer























          • Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

            – Huy Tran
            Nov 15 '18 at 22:39











          • Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

            – Bogumił Kamiński
            Nov 15 '18 at 22:42















          1














          There are several possible solutions. All of them involve different ways of sending commands to a running Julia session. The first few that come to my mind are:



          • use sockets as explained in https://docs.julialang.org/en/v1/manual/networking-and-streams/#A-simple-TCP-example-1

          • set up a HTTP server e.g. using https://github.com/JuliaWeb/HTTP.jl

          • use named pipes, as explained in Named pipe does not wait until completion in bash

          • communicate e.g. through the file system (e.g. make Julia scan some folder for .jl files and if it finds them there they get executed and moved to another folder or deleted) - this is probably simplest to implement correctly

          In all the solutions you can send the command to Julia by executing some shell command.



          No matter which approach you prefer the key challenge is sanitizing the code to handle errors properly (i.e. a situation when you sent some command to the Julia session and it crashes or when you send requests faster than Julia is able to handle them). This is especially important if you want the Julia server to be detached from the terminal.



          As a side note: when using the Distributed module from stdlib in Julia for multiprocessing you actually do a very similar thing (but the communication is Julia to Julia) so you can also have a look how this module is implemented to get the feeling how it can be done.






          share|improve this answer























          • Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

            – Huy Tran
            Nov 15 '18 at 22:39











          • Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

            – Bogumił Kamiński
            Nov 15 '18 at 22:42













          1












          1








          1







          There are several possible solutions. All of them involve different ways of sending commands to a running Julia session. The first few that come to my mind are:



          • use sockets as explained in https://docs.julialang.org/en/v1/manual/networking-and-streams/#A-simple-TCP-example-1

          • set up a HTTP server e.g. using https://github.com/JuliaWeb/HTTP.jl

          • use named pipes, as explained in Named pipe does not wait until completion in bash

          • communicate e.g. through the file system (e.g. make Julia scan some folder for .jl files and if it finds them there they get executed and moved to another folder or deleted) - this is probably simplest to implement correctly

          In all the solutions you can send the command to Julia by executing some shell command.



          No matter which approach you prefer the key challenge is sanitizing the code to handle errors properly (i.e. a situation when you sent some command to the Julia session and it crashes or when you send requests faster than Julia is able to handle them). This is especially important if you want the Julia server to be detached from the terminal.



          As a side note: when using the Distributed module from stdlib in Julia for multiprocessing you actually do a very similar thing (but the communication is Julia to Julia) so you can also have a look how this module is implemented to get the feeling how it can be done.






          share|improve this answer













          There are several possible solutions. All of them involve different ways of sending commands to a running Julia session. The first few that come to my mind are:



          • use sockets as explained in https://docs.julialang.org/en/v1/manual/networking-and-streams/#A-simple-TCP-example-1

          • set up a HTTP server e.g. using https://github.com/JuliaWeb/HTTP.jl

          • use named pipes, as explained in Named pipe does not wait until completion in bash

          • communicate e.g. through the file system (e.g. make Julia scan some folder for .jl files and if it finds them there they get executed and moved to another folder or deleted) - this is probably simplest to implement correctly

          In all the solutions you can send the command to Julia by executing some shell command.



          No matter which approach you prefer the key challenge is sanitizing the code to handle errors properly (i.e. a situation when you sent some command to the Julia session and it crashes or when you send requests faster than Julia is able to handle them). This is especially important if you want the Julia server to be detached from the terminal.



          As a side note: when using the Distributed module from stdlib in Julia for multiprocessing you actually do a very similar thing (but the communication is Julia to Julia) so you can also have a look how this module is implemented to get the feeling how it can be done.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 19:10









          Bogumił KamińskiBogumił Kamiński

          14.9k21422




          14.9k21422












          • Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

            – Huy Tran
            Nov 15 '18 at 22:39











          • Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

            – Bogumił Kamiński
            Nov 15 '18 at 22:42

















          • Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

            – Huy Tran
            Nov 15 '18 at 22:39











          • Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

            – Bogumił Kamiński
            Nov 15 '18 at 22:42
















          Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

          – Huy Tran
          Nov 15 '18 at 22:39





          Thank you. I will look into this. Currently, what I do is using a 'while(true) sleep(1)' to listen to the trigger signal file, which is kinda like a server I guess.

          – Huy Tran
          Nov 15 '18 at 22:39













          Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

          – Bogumił Kamiński
          Nov 15 '18 at 22:42





          Yes - this is something like solution four I have described, where you achieve synchronization via the file system.

          – Bogumił Kamiński
          Nov 15 '18 at 22:42













          0














          You can use include:



          julia> include("code.jl")





          share|improve this answer























          • Hi, it should be from terminal (cmd), not from the current running julia REPL.

            – Huy Tran
            Nov 15 '18 at 16:50















          0














          You can use include:



          julia> include("code.jl")





          share|improve this answer























          • Hi, it should be from terminal (cmd), not from the current running julia REPL.

            – Huy Tran
            Nov 15 '18 at 16:50













          0












          0








          0







          You can use include:



          julia> include("code.jl")





          share|improve this answer













          You can use include:



          julia> include("code.jl")






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 16:36









          fredrikekrefredrikekre

          2,0261716




          2,0261716












          • Hi, it should be from terminal (cmd), not from the current running julia REPL.

            – Huy Tran
            Nov 15 '18 at 16:50

















          • Hi, it should be from terminal (cmd), not from the current running julia REPL.

            – Huy Tran
            Nov 15 '18 at 16:50
















          Hi, it should be from terminal (cmd), not from the current running julia REPL.

          – Huy Tran
          Nov 15 '18 at 16:50





          Hi, it should be from terminal (cmd), not from the current running julia REPL.

          – Huy Tran
          Nov 15 '18 at 16:50

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323489%2fjulia-invoke-script-on-existing-repl-from-command-line%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







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands