Calling VS Code from subprocess is non blocking unlike other editors










0















I have been working on an application that spawns an editor from a script that helps edit a file in real time and save it (while the script is in progress).



It works perfectly when I use Nano, Vim or Gedit. However when I give it the argument to use VS Code then it fails. It opens the file in VS Code, then proceeds to the next line in the script, whereas for others its blocking, which is what I want.

Sample Code:



import subprocess

subprocess.run(['code', 'code.txt'])
subprocess.run(['nano', 'nano.text'])
subprocess.run(['vi', 'vim.txt'])
subprocess.run(['gedit', 'gedit.txt'])


Behaviour

When running this script in terminal, firstly the VS Code tab opens, however the terminal opens nano. Then you write and save something in nano and as soon as you close it, vim opens and similarly gedit. When you finally close gedit, you get a new prompt.

However, if you change the code to open VS Code in the end, then the terminal with show a new prompt, without even saving and closing your file opened in VS Code.



What is the reason behind behavior?










share|improve this question
























  • That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

    – Srini
    Nov 13 '18 at 19:45











  • Interestingly enough gvim is not bound to the process that launched it

    – Srini
    Nov 13 '18 at 19:45











  • @Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

    – jar
    Nov 13 '18 at 19:50











  • I haven't really answered your question. So you should probably wait for someone who has a better answer :)

    – Srini
    Nov 13 '18 at 20:01















0















I have been working on an application that spawns an editor from a script that helps edit a file in real time and save it (while the script is in progress).



It works perfectly when I use Nano, Vim or Gedit. However when I give it the argument to use VS Code then it fails. It opens the file in VS Code, then proceeds to the next line in the script, whereas for others its blocking, which is what I want.

Sample Code:



import subprocess

subprocess.run(['code', 'code.txt'])
subprocess.run(['nano', 'nano.text'])
subprocess.run(['vi', 'vim.txt'])
subprocess.run(['gedit', 'gedit.txt'])


Behaviour

When running this script in terminal, firstly the VS Code tab opens, however the terminal opens nano. Then you write and save something in nano and as soon as you close it, vim opens and similarly gedit. When you finally close gedit, you get a new prompt.

However, if you change the code to open VS Code in the end, then the terminal with show a new prompt, without even saving and closing your file opened in VS Code.



What is the reason behind behavior?










share|improve this question
























  • That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

    – Srini
    Nov 13 '18 at 19:45











  • Interestingly enough gvim is not bound to the process that launched it

    – Srini
    Nov 13 '18 at 19:45











  • @Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

    – jar
    Nov 13 '18 at 19:50











  • I haven't really answered your question. So you should probably wait for someone who has a better answer :)

    – Srini
    Nov 13 '18 at 20:01













0












0








0








I have been working on an application that spawns an editor from a script that helps edit a file in real time and save it (while the script is in progress).



It works perfectly when I use Nano, Vim or Gedit. However when I give it the argument to use VS Code then it fails. It opens the file in VS Code, then proceeds to the next line in the script, whereas for others its blocking, which is what I want.

Sample Code:



import subprocess

subprocess.run(['code', 'code.txt'])
subprocess.run(['nano', 'nano.text'])
subprocess.run(['vi', 'vim.txt'])
subprocess.run(['gedit', 'gedit.txt'])


Behaviour

When running this script in terminal, firstly the VS Code tab opens, however the terminal opens nano. Then you write and save something in nano and as soon as you close it, vim opens and similarly gedit. When you finally close gedit, you get a new prompt.

However, if you change the code to open VS Code in the end, then the terminal with show a new prompt, without even saving and closing your file opened in VS Code.



What is the reason behind behavior?










share|improve this question
















I have been working on an application that spawns an editor from a script that helps edit a file in real time and save it (while the script is in progress).



It works perfectly when I use Nano, Vim or Gedit. However when I give it the argument to use VS Code then it fails. It opens the file in VS Code, then proceeds to the next line in the script, whereas for others its blocking, which is what I want.

Sample Code:



import subprocess

subprocess.run(['code', 'code.txt'])
subprocess.run(['nano', 'nano.text'])
subprocess.run(['vi', 'vim.txt'])
subprocess.run(['gedit', 'gedit.txt'])


Behaviour

When running this script in terminal, firstly the VS Code tab opens, however the terminal opens nano. Then you write and save something in nano and as soon as you close it, vim opens and similarly gedit. When you finally close gedit, you get a new prompt.

However, if you change the code to open VS Code in the end, then the terminal with show a new prompt, without even saving and closing your file opened in VS Code.



What is the reason behind behavior?







python python-3.x visual-studio-code subprocess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 19:45







jar

















asked Nov 13 '18 at 19:23









jarjar

669418




669418












  • That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

    – Srini
    Nov 13 '18 at 19:45











  • Interestingly enough gvim is not bound to the process that launched it

    – Srini
    Nov 13 '18 at 19:45











  • @Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

    – jar
    Nov 13 '18 at 19:50











  • I haven't really answered your question. So you should probably wait for someone who has a better answer :)

    – Srini
    Nov 13 '18 at 20:01

















  • That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

    – Srini
    Nov 13 '18 at 19:45











  • Interestingly enough gvim is not bound to the process that launched it

    – Srini
    Nov 13 '18 at 19:45











  • @Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

    – jar
    Nov 13 '18 at 19:50











  • I haven't really answered your question. So you should probably wait for someone who has a better answer :)

    – Srini
    Nov 13 '18 at 20:01
















That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

– Srini
Nov 13 '18 at 19:45





That's not a python problem. That's just how VS code works, code nohups itself from the process that launched it. Try running gedit or vim from the terminal and try killing the terminal, vim would die too. Gedit(Gnome) and Kate(KDE) block and do not nohup.

– Srini
Nov 13 '18 at 19:45













Interestingly enough gvim is not bound to the process that launched it

– Srini
Nov 13 '18 at 19:45





Interestingly enough gvim is not bound to the process that launched it

– Srini
Nov 13 '18 at 19:45













@Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

– jar
Nov 13 '18 at 19:50





@Srini I did not know that. Thanks. If you want you can answer this question, maybe provide a link or a bit of explanation. I will accept it. Or should I delete this question?

– jar
Nov 13 '18 at 19:50













I haven't really answered your question. So you should probably wait for someone who has a better answer :)

– Srini
Nov 13 '18 at 20:01





I haven't really answered your question. So you should probably wait for someone who has a better answer :)

– Srini
Nov 13 '18 at 20:01












0






active

oldest

votes











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%2f53288147%2fcalling-vs-code-from-subprocess-is-non-blocking-unlike-other-editors%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f53288147%2fcalling-vs-code-from-subprocess-is-non-blocking-unlike-other-editors%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党