Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29615 > unrolled thread
| Started by | janis.judvaitis@gmail.com |
|---|---|
| First post | 2012-09-21 02:13 -0700 |
| Last post | 2012-09-25 01:05 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.python
Seome kind of unblocking input janis.judvaitis@gmail.com - 2012-09-21 02:13 -0700
Re: Seome kind of unblocking input Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-21 15:54 -0400
Re: Seome kind of unblocking input Ramchandra Apte <maniandram01@gmail.com> - 2012-09-23 08:49 -0700
Re: Seome kind of unblocking input Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-23 18:13 +0100
Re: Seome kind of unblocking input Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-23 13:50 -0400
Re: Seome kind of unblocking input Ramchandra Apte <maniandram01@gmail.com> - 2012-09-23 22:31 -0700
Re: Seome kind of unblocking input Ramchandra Apte <maniandram01@gmail.com> - 2012-09-23 22:31 -0700
Re: Seome kind of unblocking input Chris Angelico <rosuav@gmail.com> - 2012-09-24 15:14 +1000
Re: Seome kind of unblocking input Ramchandra Apte <maniandram01@gmail.com> - 2012-09-23 08:49 -0700
Re: Seome kind of unblocking input janis.judvaitis@gmail.com - 2012-09-25 01:05 -0700
| From | janis.judvaitis@gmail.com |
|---|---|
| Date | 2012-09-21 02:13 -0700 |
| Subject | Seome kind of unblocking input |
| Message-ID | <0be9b4c2-b661-4709-ba8f-40a6f78ad634@googlegroups.com> |
Hello! I'm building small console like program for embedded system control over serial port. Naturally I need to be able to recieve commands from user and print reply's from embedded device. Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. Note 2: I've readed about ways to make nonblocking input by reading single char etc. but that's is all messy and very platform dependent, I would love to have platform independent solution. Thanks in advance! --JJ
[toc] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-09-21 15:54 -0400 |
| Message-ID | <mailman.1030.1348257285.27098.python-list@python.org> |
| In reply to | #29615 |
On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis@gmail.com
declaimed the following in gmane.comp.python.general:
> Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this??
>
> Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread.
>
Confusion abounds...
You don't have to "pickle file like object..." for it to be used by
a Python THREAD... But your mention of pipes makes me think you are
using subprocesses and/or multiprocessing modules. Threads run in a
shared environment (you may need to put a lock around the file object so
that only one thread at a time does the I/O on that object), but
processes are independent memory spaces.
However, you may also encounter OS specific behavior WRT
stdout/stderr when they are connected to a console. The OS itself may
block/buffer output when there is a pending input on the same console.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Ramchandra Apte <maniandram01@gmail.com> |
|---|---|
| Date | 2012-09-23 08:49 -0700 |
| Message-ID | <593f9c45-9150-4d37-9c9c-e3cd66ed2d8e@googlegroups.com> |
| In reply to | #29667 |
On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis@gmail.com > > declaimed the following in gmane.comp.python.general: > > > > > Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? > > > > > > Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. > > > > > > > Confusion abounds... > > > > You don't have to "pickle file like object..." for it to be used by > > a Python THREAD... But your mention of pipes makes me think you are > > using subprocesses and/or multiprocessing modules. Threads run in a > > shared environment (you may need to put a lock around the file object so > > that only one thread at a time does the I/O on that object), but > > processes are independent memory spaces. > > > > However, you may also encounter OS specific behavior WRT > > stdout/stderr when they are connected to a console. The OS itself may > > block/buffer output when there is a pending input on the same console. > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ You can clear the buffer by calling file.flush()
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-09-23 18:13 +0100 |
| Message-ID | <mailman.1131.1348420508.27098.python-list@python.org> |
| In reply to | #29817 |
On 23/09/2012 16:49, Ramchandra Apte wrote: > On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: >> On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis@gmail.com >> >> declaimed the following in gmane.comp.python.general: >> >> >> >>> Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? >> >>> >> >>> Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. >> >>> >> >> >> >> Confusion abounds... >> >> >> >> You don't have to "pickle file like object..." for it to be used by >> >> a Python THREAD... But your mention of pipes makes me think you are >> >> using subprocesses and/or multiprocessing modules. Threads run in a >> >> shared environment (you may need to put a lock around the file object so >> >> that only one thread at a time does the I/O on that object), but >> >> processes are independent memory spaces. >> >> >> >> However, you may also encounter OS specific behavior WRT >> >> stdout/stderr when they are connected to a console. The OS itself may >> >> block/buffer output when there is a pending input on the same console. >> >> -- >> >> Wulfraed Dennis Lee Bieber AF6VN >> >> wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > You can clear the buffer by calling file.flush() > Shock, horror, probe, well I never did. I'm sure that everyone is updating their Xmas and birthday card lists to ensure that you're not missed out having furnished a piece of information that doubtless not one other person on this group knew. -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-09-23 13:50 -0400 |
| Message-ID | <mailman.1135.1348422637.27098.python-list@python.org> |
| In reply to | #29817 |
On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence
<breamoreboy@yahoo.co.uk> declaimed the following in
gmane.comp.python.general:
> On 23/09/2012 16:49, Ramchandra Apte wrote:
> > You can clear the buffer by calling file.flush()
> >
>
> Shock, horror, probe, well I never did. I'm sure that everyone is
> updating their Xmas and birthday card lists to ensure that you're not
> missed out having furnished a piece of information that doubtless not
> one other person on this group knew.
It probably wouldn't have helped either... The OP was looking for,
as I recall, some means by which a pending input would not block other
output on a console... So what use is flushing a buffer?
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Ramchandra Apte <maniandram01@gmail.com> |
|---|---|
| Date | 2012-09-23 22:31 -0700 |
| Message-ID | <16a8f7bb-a392-48e1-94c5-4fd678ebf63f@googlegroups.com> |
| In reply to | #29835 |
On Sunday, 23 September 2012 23:20:37 UTC+5:30, Dennis Lee Bieber wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > > <breamoreboy@yahoo.co.uk> declaimed the following in > > gmane.comp.python.general: > > > > > On 23/09/2012 16:49, Ramchandra Apte wrote: > > > > > > You can clear the buffer by calling file.flush() > > > > > > > > > > Shock, horror, probe, well I never did. I'm sure that everyone is > > > updating their Xmas and birthday card lists to ensure that you're not > > > missed out having furnished a piece of information that doubtless not > > > one other person on this group knew. > > > > It probably wouldn't have helped either... The OP was looking for, > > as I recall, some means by which a pending input would not block other > > output on a console... So what use is flushing a buffer? > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Okay okay! My message was out-of-context. Anyways, nobody in my age group knows that you can clear the buffer of a file in Python by calling file.flush().
[toc] | [prev] | [next] | [standalone]
| From | Ramchandra Apte <maniandram01@gmail.com> |
|---|---|
| Date | 2012-09-23 22:31 -0700 |
| Message-ID | <mailman.1182.1348464713.27098.python-list@python.org> |
| In reply to | #29835 |
On Sunday, 23 September 2012 23:20:37 UTC+5:30, Dennis Lee Bieber wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > > <breamoreboy@yahoo.co.uk> declaimed the following in > > gmane.comp.python.general: > > > > > On 23/09/2012 16:49, Ramchandra Apte wrote: > > > > > > You can clear the buffer by calling file.flush() > > > > > > > > > > Shock, horror, probe, well I never did. I'm sure that everyone is > > > updating their Xmas and birthday card lists to ensure that you're not > > > missed out having furnished a piece of information that doubtless not > > > one other person on this group knew. > > > > It probably wouldn't have helped either... The OP was looking for, > > as I recall, some means by which a pending input would not block other > > output on a console... So what use is flushing a buffer? > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Okay okay! My message was out-of-context. Anyways, nobody in my age group knows that you can clear the buffer of a file in Python by calling file.flush().
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-09-24 15:14 +1000 |
| Message-ID | <mailman.1181.1348463659.27098.python-list@python.org> |
| In reply to | #29817 |
On Mon, Sep 24, 2012 at 3:50 AM, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: > On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence > <breamoreboy@yahoo.co.uk> declaimed the following in > gmane.comp.python.general: > >> On 23/09/2012 16:49, Ramchandra Apte wrote: > >> > You can clear the buffer by calling file.flush() >> > >> >> Shock, horror, probe, well I never did. I'm sure that everyone is >> updating their Xmas and birthday card lists to ensure that you're not >> missed out having furnished a piece of information that doubtless not >> one other person on this group knew. > > It probably wouldn't have helped either... The OP was looking for, > as I recall, some means by which a pending input would not block other > output on a console... So what use is flushing a buffer? It all depends on *why* pending input appears to be blocking other output. I say "appears to be" because buffered output can indeed appear to be blocked, but so can other things. Flushing output is an easy thing to try. If it fails, back to square one, but with more knowledge. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ramchandra Apte <maniandram01@gmail.com> |
|---|---|
| Date | 2012-09-23 08:49 -0700 |
| Message-ID | <mailman.1121.1348415394.27098.python-list@python.org> |
| In reply to | #29667 |
On Saturday, 22 September 2012 01:24:46 UTC+5:30, Dennis Lee Bieber wrote: > On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), janis.judvaitis@gmail.com > > declaimed the following in gmane.comp.python.general: > > > > > Since I'm using threads and pipes everything works ok, except that when i call input() there is no way that I could print something, is there any workaround for this?? > > > > > > Note: I don't need to catch any key's before enter or smtng, just be able to print while input() is waiting. I'm thinking that maybe there is a way for two threads to share one stdout, which should resolve this, but I can't make it work, since U can't pickle file like object(stdout) to pass it to other thread. > > > > > > > Confusion abounds... > > > > You don't have to "pickle file like object..." for it to be used by > > a Python THREAD... But your mention of pipes makes me think you are > > using subprocesses and/or multiprocessing modules. Threads run in a > > shared environment (you may need to put a lock around the file object so > > that only one thread at a time does the I/O on that object), but > > processes are independent memory spaces. > > > > However, you may also encounter OS specific behavior WRT > > stdout/stderr when they are connected to a console. The OS itself may > > block/buffer output when there is a pending input on the same console. > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ You can clear the buffer by calling file.flush()
[toc] | [prev] | [next] | [standalone]
| From | janis.judvaitis@gmail.com |
|---|---|
| Date | 2012-09-25 01:05 -0700 |
| Message-ID | <784ead86-fc92-48e6-a34e-378a7010c0d5@googlegroups.com> |
| In reply to | #29615 |
Thanks for reply's. I'll be looking into threading, it seems like right way to go. btw. Why Python developers don't make a wrapper for input() with callback function using threads, so people can easily use nonblocking input?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web