Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Seome kind of unblocking input

Reply
Thread Tools

Seome kind of unblocking input

 
 
janis.judvaitis@gmail.com
Guest
Posts: n/a
 
      09-21-2012
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 loveto have platform independent solution.

Thanks in advance!

--JJ
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-21-2012
On Fri, 21 Sep 2012 02:13:28 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed)
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
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
Ramchandra Apte
Guest
Posts: n/a
 
      09-23-2012
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), (E-Mail Removed)
>
> declaimed the following in gmane.comp.python.general:
>
>
>
> > Since I'm using threads and pipes everything works ok, except that wheni 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
>
> (E-Mail Removed) HTTP://wlfraed.home.netcom.com/


You can clear the buffer by calling file.flush()
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      09-23-2012
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), (E-Mail Removed)
>
> declaimed the following in gmane.comp.python.general:
>
>
>
> > Since I'm using threads and pipes everything works ok, except that wheni 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
>
> (E-Mail Removed) HTTP://wlfraed.home.netcom.com/


You can clear the buffer by calling file.flush()
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      09-23-2012
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), (E-Mail Removed)
>>
>> 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
>>
>> (E-Mail Removed) 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.

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      09-24-2012
On Mon, Sep 24, 2012 at 3:50 AM, Dennis Lee Bieber
<(E-Mail Removed)> wrote:
> On Sun, 23 Sep 2012 18:13:57 +0100, Mark Lawrence
> <(E-Mail Removed)> 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
 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      09-24-2012
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
>
> <(E-Mail Removed)> 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
>
> (E-Mail Removed) 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().
 
Reply With Quote
 
janis.judvaitis@gmail.com
Guest
Posts: n/a
 
      09-25-2012
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unblocking images from FF? iamu@me.com Firefox 1 03-05-2006 08:26 PM
Unblocking mobile UK Wayne Kerr Computer Support 4 08-18-2005 08:02 AM
unblocking pictures sad-eyed lady Computer Support 18 06-10-2005 03:09 AM
unblocking firewall Eli Aran Computer Support 5 01-24-2005 08:33 PM
unblocking email David Smalley Microsoft Certification 2 01-23-2004 10:16 PM



Advertisments