This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年07月26日 10:57 by Barney Stratford, last changed 2022年04月11日 14:58 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| patch.txt | Barney Stratford, 2015年07月26日 10:57 | review | ||
| patch.txt | Barney Stratford, 2015年08月02日 16:37 | review | ||
| Messages (4) | |||
|---|---|---|---|
| msg247424 - (view) | Author: Barney Stratford (Barney Stratford) * | Date: 2015年07月26日 10:57 | |
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): def describe (indicator): if readline.reading_line (): print () print (indicator.description) readline.forced_update_display () else: print (indicator.description) I have read PEP7, and have made patchtest on my patch. |
|||
| msg247849 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年08月02日 01:30 | |
Suggest you integrate your rl_forced_update_display() wrapper and documentation with the existing patches in Issue 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? |
|||
| msg247881 - (view) | Author: Barney Stratford (Barney Stratford) * | Date: 2015年08月02日 16:37 | |
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. reading_lock = threading.Lock () readline.set_lock (reading_lock) def describe (indicator): if reading_lock.acquire (False): print (indicator.description) reading_lock.release () else: print () print (indicator.description) readline.forced_update_display () |
|||
| msg268965 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2016年06月21日 04:23 | |
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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:19 | admin | set | github: 68915 |
| 2016年06月21日 04:23:10 | martin.panter | set | title: Expand readline module -> Wrap rl_forced_update_display() and lock readline module while active messages: + msg268965 stage: patch review |
| 2015年08月02日 16:37:23 | Barney Stratford | set | files:
+ patch.txt messages: + msg247881 |
| 2015年08月02日 01:30:30 | martin.panter | set | nosy:
+ martin.panter dependencies: + Export readline forced_update_display messages: + msg247849 |
| 2015年07月27日 17:43:43 | r.david.murray | set | versions: - Python 3.5 |
| 2015年07月26日 17:06:39 | ned.deily | set | nosy:
+ twouters |
| 2015年07月26日 12:46:08 | Barney Stratford | set | components: + Extension Modules, - Library (Lib) |
| 2015年07月26日 10:57:51 | Barney Stratford | create | |