Python 2.7 script using curses being automatically backgrounded when halfdelay or cbreak is called

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












I am currently working on modernizing (was made on Trusty 14.04, modernizing for Bionic 18.04) a python script that uses curses to create a menu for a user. During the initial launch of the script before the actual UI is displayed there is a line:



curses.halfdelay(10)


(The documentation for this command can be found here) This line is preceded by a curses.initscr() so there should be a valid terminal to receive input from. The problem is that this exact line causes the script to be backgrounded and you have to fg the process to continue the execution. After the fg, the delay specified in the halfdelay will take place and then the script will continue normally which suggests the backgrounding takes place before actually waiting for any characters. For reference, the script works perfectly fine in Ubuntu 14.04, so I am inclined to say it is a problem due to a change in the way getty works or a change in behaviour from upstart to systemd. I have found that replacing the line halfdelay with curses.cbreak() instead also causes it to be backgrounded. Since halfdelay essentially causes the terminal to switch in to cbreak mode, that suggests to me that this is what is causing the issue. I have been unable to find anyone online having an even remotely similar issue so any help would be appreciated.



Thanks!







share|improve this question























    up vote
    0
    down vote

    favorite












    I am currently working on modernizing (was made on Trusty 14.04, modernizing for Bionic 18.04) a python script that uses curses to create a menu for a user. During the initial launch of the script before the actual UI is displayed there is a line:



    curses.halfdelay(10)


    (The documentation for this command can be found here) This line is preceded by a curses.initscr() so there should be a valid terminal to receive input from. The problem is that this exact line causes the script to be backgrounded and you have to fg the process to continue the execution. After the fg, the delay specified in the halfdelay will take place and then the script will continue normally which suggests the backgrounding takes place before actually waiting for any characters. For reference, the script works perfectly fine in Ubuntu 14.04, so I am inclined to say it is a problem due to a change in the way getty works or a change in behaviour from upstart to systemd. I have found that replacing the line halfdelay with curses.cbreak() instead also causes it to be backgrounded. Since halfdelay essentially causes the terminal to switch in to cbreak mode, that suggests to me that this is what is causing the issue. I have been unable to find anyone online having an even remotely similar issue so any help would be appreciated.



    Thanks!







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am currently working on modernizing (was made on Trusty 14.04, modernizing for Bionic 18.04) a python script that uses curses to create a menu for a user. During the initial launch of the script before the actual UI is displayed there is a line:



      curses.halfdelay(10)


      (The documentation for this command can be found here) This line is preceded by a curses.initscr() so there should be a valid terminal to receive input from. The problem is that this exact line causes the script to be backgrounded and you have to fg the process to continue the execution. After the fg, the delay specified in the halfdelay will take place and then the script will continue normally which suggests the backgrounding takes place before actually waiting for any characters. For reference, the script works perfectly fine in Ubuntu 14.04, so I am inclined to say it is a problem due to a change in the way getty works or a change in behaviour from upstart to systemd. I have found that replacing the line halfdelay with curses.cbreak() instead also causes it to be backgrounded. Since halfdelay essentially causes the terminal to switch in to cbreak mode, that suggests to me that this is what is causing the issue. I have been unable to find anyone online having an even remotely similar issue so any help would be appreciated.



      Thanks!







      share|improve this question











      I am currently working on modernizing (was made on Trusty 14.04, modernizing for Bionic 18.04) a python script that uses curses to create a menu for a user. During the initial launch of the script before the actual UI is displayed there is a line:



      curses.halfdelay(10)


      (The documentation for this command can be found here) This line is preceded by a curses.initscr() so there should be a valid terminal to receive input from. The problem is that this exact line causes the script to be backgrounded and you have to fg the process to continue the execution. After the fg, the delay specified in the halfdelay will take place and then the script will continue normally which suggests the backgrounding takes place before actually waiting for any characters. For reference, the script works perfectly fine in Ubuntu 14.04, so I am inclined to say it is a problem due to a change in the way getty works or a change in behaviour from upstart to systemd. I have found that replacing the line halfdelay with curses.cbreak() instead also causes it to be backgrounded. Since halfdelay essentially causes the terminal to switch in to cbreak mode, that suggests to me that this is what is causing the issue. I have been unable to find anyone online having an even remotely similar issue so any help would be appreciated.



      Thanks!









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 6 at 15:40









      user1487162

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          The issue was that curses was trying to hijack tty1 (which was already in use) and therefore in order to prevent the current terminal from being hijacked the OS backgrounds the problem






          share|improve this answer





















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1044205%2fpython-2-7-script-using-curses-being-automatically-backgrounded-when-halfdelay-o%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            The issue was that curses was trying to hijack tty1 (which was already in use) and therefore in order to prevent the current terminal from being hijacked the OS backgrounds the problem






            share|improve this answer

























              up vote
              0
              down vote













              The issue was that curses was trying to hijack tty1 (which was already in use) and therefore in order to prevent the current terminal from being hijacked the OS backgrounds the problem






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                The issue was that curses was trying to hijack tty1 (which was already in use) and therefore in order to prevent the current terminal from being hijacked the OS backgrounds the problem






                share|improve this answer













                The issue was that curses was trying to hijack tty1 (which was already in use) and therefore in order to prevent the current terminal from being hijacked the OS backgrounds the problem







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jun 6 at 19:01









                user1487162

                1




                1






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1044205%2fpython-2-7-script-using-curses-being-automatically-backgrounded-when-halfdelay-o%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491