Python 2.7 script using curses being automatically backgrounded when halfdelay or cbreak is called
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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!
scripts python 18.04 execute-command ncurses
add a comment |Â
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!
scripts python 18.04 execute-command ncurses
add a comment |Â
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!
scripts python 18.04 execute-command ncurses
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!
scripts python 18.04 execute-command ncurses
asked Jun 6 at 15:40
user1487162
1
1
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Jun 6 at 19:01
user1487162
1
1
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password