Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91083 > unrolled thread
| Started by | Benjamin Risher <brisher777@gmail.com> |
|---|---|
| First post | 2015-05-22 17:27 -0700 |
| Last post | 2015-05-23 02:41 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
remote control of a cmd.Cmd() loop (help requested) Benjamin Risher <brisher777@gmail.com> - 2015-05-22 17:27 -0700
Re: remote control of a cmd.Cmd() loop (help requested) MRAB <python@mrabarnett.plus.com> - 2015-05-23 02:41 +0100
| From | Benjamin Risher <brisher777@gmail.com> |
|---|---|
| Date | 2015-05-22 17:27 -0700 |
| Subject | remote control of a cmd.Cmd() loop (help requested) |
| Message-ID | <d19c254b-7983-4862-9ab1-9ac45df841c1@googlegroups.com> |
First, the snippet provided is a contrived example of a much larger program. http://pastebin.com/xRqBE5BY (written in python3 with access to 3.4 if necessary) The goal: To connect to a listening socket and send commands to the cmd.Cmd() loop running, then show the output to both stdout and the remote connection. Right now, I have a solution that will work as long as everything that needs to get sent to stdout and the socket is return'd from each function instead of printed. Because this is already a larger project, I would prefer not to have to go back through and refactor everything to facilitate the remote control (the actual program involves threading and locks etc etc). I feel like there should be a fairly simple solution dealing with duplicating the file descriptor or something similar. I've messed around trying to find something like that, but without success. I've also looked into the contextlib.redirect_stdout, but it expects a file type object. Also, using socket.makefile() results in the returned object not having a fileno() method, so I can't use select on it. Basically, I'm hoping someone here knows some file descriptor-fu or some other cleaner solution. Any help would be appreciated! remote display ------------- | ------------ menu display $>nc localhost 12345 | s function called. s | h function called. s function called. | Traceback ... h | 44: 'NoneType' object has no attribute 'strip' $>
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2015-05-23 02:41 +0100 |
| Message-ID | <mailman.247.1432345304.17265.python-list@python.org> |
| In reply to | #91083 |
On 2015-05-23 01:27, Benjamin Risher wrote: > First, the snippet provided is a contrived example of a much larger program. > > http://pastebin.com/xRqBE5BY > > (written in python3 with access to 3.4 if necessary) > > The goal: To connect to a listening socket and send commands to the cmd.Cmd() loop running, then show the output to both stdout and the remote connection. > > Right now, I have a solution that will work as long as everything that needs to get sent to stdout and the socket is return'd from each function instead of printed. > > Because this is already a larger project, I would prefer not to have to go back through and refactor everything to facilitate the remote control (the actual program involves threading and locks etc etc). > > I feel like there should be a fairly simple solution dealing with duplicating the file descriptor or something similar. I've messed around trying to find something like that, but without success. > > I've also looked into the contextlib.redirect_stdout, but it expects a file type object. Also, using socket.makefile() results in the returned object not having a fileno() method, so I can't use select on it. > > Basically, I'm hoping someone here knows some file descriptor-fu or some other cleaner solution. > > Any help would be appreciated! > > > remote display ------------- | ------------ menu display > > $>nc localhost 12345 | s function called. > s | h function called. > s function called. | Traceback ... > h | 44: 'NoneType' object has no attribute 'strip' > > $> > You could replace the current sys.stdout object with your own object that copies to the original sys.stdout object and the socket.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web