Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Seome kind of unblocking input

17 views
Skip to first unread message

janis.j...@gmail.com

unread,
Sep 21, 2012, 5:13:28 AM9/21/12
to
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
Message has been deleted

Ramchandra Apte

unread,
Sep 23, 2012, 11:49:44 AM9/23/12
to pytho...@python.org
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.j...@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
>
> wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

You can clear the buffer by calling file.flush()

Ramchandra Apte

unread,
Sep 23, 2012, 11:49:44 AM9/23/12
to comp.lan...@googlegroups.com, pytho...@python.org
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.j...@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.
>
> >
>
>
>

Mark Lawrence

unread,
Sep 23, 2012, 1:13:57 PM9/23/12
to pytho...@python.org
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.

Message has been deleted

Chris Angelico

unread,
Sep 24, 2012, 1:14:16 AM9/24/12
to pytho...@python.org
On Mon, Sep 24, 2012 at 3:50 AM, Dennis Lee Bieber
<wlf...@ix.netcom.com> wrote:
> On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence
> <bream...@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

Ramchandra Apte

unread,
Sep 24, 2012, 1:31:50 AM9/24/12
to pytho...@python.org
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
>
> <bream...@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
>
> wlf...@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().

Ramchandra Apte

unread,
Sep 24, 2012, 1:31:50 AM9/24/12
to comp.lan...@googlegroups.com, pytho...@python.org
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
>
> <bream...@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
>
> wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/


janis.j...@gmail.com

unread,
Sep 25, 2012, 4:05:54 AM9/25/12
to
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?
0 new messages