You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrap rl_forced_update_display() and lock readline module while active #68915
I have a use case where a daemon thread needs to write periodic updates to sys.stdout. I'd prefer it not to print in the middle of a command being typed. In order to achieve this, I have added to the readline module. There is now a function to determine whether we are reading a line, and one to call rl_forced_update_display. These functions enable me to say (in the daemon thread):
Suggest you integrate your rl_forced_update_display() wrapper and documentation with the existing patches in bpo-23067.
Regarding the reading_line() flag, your use case seems a bit racy to me. Can’t the other thread start reading a line after reading_line() returns false and before your print() statement happens?
BarneyStratford commented on Aug 2, 2015
BarneyStratfordmannequin
MannequinAuthor
More actions
You're absolutely right. I had elided the details of the locking from my original use case, but now I look at it again, I see that even what I did have wasn't enough.
I've made a new patch that takes a lock properly. A non-blocking acquisition of the lock will serve the same purpose as looking to see if there is a line being read, and will also prevent the interpreter from starting to read a new line while the text is being printed.
Activity
BarneyStratford commentedon Jul 26, 2015
I have a use case where a daemon thread needs to write periodic updates to sys.stdout. I'd prefer it not to print in the middle of a command being typed. In order to achieve this, I have added to the readline module. There is now a function to determine whether we are reading a line, and one to call rl_forced_update_display. These functions enable me to say (in the daemon thread):
I have read PEP-7, and have made patchtest on my patch.
vadmium commentedon Aug 2, 2015
Suggest you integrate your rl_forced_update_display() wrapper and documentation with the existing patches in bpo-23067.
Regarding the reading_line() flag, your use case seems a bit racy to me. Can’t the other thread start reading a line after reading_line() returns false and before your print() statement happens?
BarneyStratford commentedon Aug 2, 2015
You're absolutely right. I had elided the details of the locking from my original use case, but now I look at it again, I see that even what I did have wasn't enough.
I've made a new patch that takes a lock properly. A non-blocking acquisition of the lock will serve the same purpose as looking to see if there is a line being read, and will also prevent the interpreter from starting to read a new line while the text is being printed.
My use case now looks like this.
vadmium commentedon Jun 21, 2016
I wonder why you can’t add the locking around input() calls at a higher level, rather than needing to change the readline module itself.
[-]Expand readline module[/-][+]Wrap rl_forced_update_display() and lock readline module while active[/+]