Delays getting data on sys.stdin.readline() ?

2005-11-19 Thread Christian Convey
Hello,

I've got a program that (ideally) perpetually monitors sys.stdin for
lines of text. As soon as a line comes in, my program takes some
action.

The problem is, it seems like a very large amount of data must
accumulate on sys.stdin before even my first invocation of readline()
returns.  This delay prevents my program from being responsive in the
way it must be.

Has anyone else seen this effect?  If so, is there a reasonable workaround?

Thanks very much,
Christian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delays getting data on sys.stdin.readline() ?

2005-11-20 Thread Christian Convey
On 11/19/05, Mike Meyer <[EMAIL PROTECTED]> wrote:
> Christian Convey <[EMAIL PROTECTED]> writes:
> > I've got a program that (ideally) perpetually monitors sys.stdin for
> > lines of text. As soon as a line comes in, my program takes some
> > action.
> > The problem is, it seems like a very large amount of data must
> > accumulate on sys.stdin before even my first invocation of readline()
> > returns.  This delay prevents my program from being responsive in the
> > way it must be.
>
> readline normally returns as soon as it sees a newline. External
> conditions may cause this to change, or make it impossible. Without
> knowing those external conditions, the best we can do is guess as to
> what might be the problem.
>
> > Has anyone else seen this effect?  If so, is there a reasonable workaround?
>
> Yes, and maybe. Depends on what's causing the problem. Tell us more
> about the program, and what sys.stdin is connected to, and the
> platform you're running on, and someone should be able to provide
> explicit information.

OK, I've fixed it, but I don't understand why the fix works.

Let's say I've got two Python programs, I'll call "producer" and
"consumer". "producer" runs for a long time and occasionally while
running sends lines of text to stdout. "consumer" is typically blocked
in a call to sys.stdin.readline().

When I run "producer" on its own, I see its output appear on the
console pretty much immediately after calling the "print" command.

But when I pipe "producer"s output to "consumer"s stdin on the Linux
command line, "consumer" stays blocked on its first call to
sys.stdin.readline() until the "producer" program terminates. At that
point, "consumer" seems to immediately get access to all of the stdout
produced by "producer".

I've found I can fix this problem by modifying "producer" so that
immediately after each "print" command, I call sys.stdout.flush(). 
When I make this modification, I find that "consumer" has access to
the output of "producer" immediately after "producer" issues a "print"
statement.

So here's what I don't get: If "producer" was retaining its output for
a while for the sake of efficiency, I would expect to see that effect
when I just run "producer" on the command line. That is, I would
expect the console to not show any output from "producer" until
"producer" terminates.  But instead, I see the output immediately. So
why, when I pipe the output to "consumer", doesn't "consumer" get
access to that data as its produced unless "consumer" is explicitely
calling sys.stdout.flush().

Any thoughts?

Thanks,
Christian
-- 
http://mail.python.org/mailman/listinfo/python-list


Status of optional static typing in Python?

2006-06-22 Thread Christian Convey
Hi guys,

I'm looking at developing a somewhat complex system, and I think some 
static typing will help me keep limit my confusion.  I.e.:

http://www.artima.com/weblogs/viewpost.jsp?thread=87182

Does anyone know if/when that feature may become part of Python?

Thanks very much,
Christian


-- 
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: better Python IDE? Mimics Maya's script editor?

2006-06-22 Thread Christian Convey
Ten wrote:
> If you get into emacs, it's worth the time invested. The learning curve's 
> alleged to be steep, but it isn't that bad, I use it and I'm as dumb as a 
> stump. It's a very good IDE for everyday use.  :-)

Not to get into the classic emacs/vi/etc. argument, but from my 
experience emacs has never been a good learning investment.

For an editor (on Linux) I just use Kate or Gedit, which have syntax 
highlighting.  For debugging, I use the print statement, because I 
haven't found an interactive debugger that I like.

I did try Eclipse's "PyDev" module.  It was OK, but I found Eclipse to 
have so much screen clutter and so-so responsiveness, so I decided to 
not keep on using it.

KDevelop now has support for Python coding, but no Python debugger yet. 
  It also doesn't support tab completions for Python (that I'm aware of).

So for now, I've found just a plain old text editor, plus print 
statements, to be the right choice for me.

-- 
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Status of optional static typing in Python?

2006-06-22 Thread Christian Convey
Perhaps I'm deluded but I don't think so.  I'll tell you my situation 
and I'd appreciate your take on it...

I'm looking into the design a network simulator.  The simulator has a 
few requirements:

(1) I need to be able to swap in a variety of replacement components 
during different simulations.  I.e., RadioFrequencyChannelModel, 
WiredNetworkChannelModel, etc.  This drives me to want the notion of 
inherited interfaces, partly as a form of documentation.

(2) I want a form of encapsulation (which I realize isn't necessarily 
guaranteed in all possible static typing implementations).  I.e., I want 
to ensure that any code which accesses a ChannelModel only calls those 
methods that are part of the ChannelModel interface.  If there's a 
method RadioFrequencyChannelModel.setBroadcastDistance(...), which isn't 
part of the generic ChannelModel interface, I don't want most of my code 
to be able to start using that particular method, if the code need to be 
able to work with all possible ChannelModel implementations.

(3) I like Interfaces as a matter of documentation.  It helps me to 
thing things through.  I've got a lot of components that must support 
interchangeable implementations: channels, modems, MAC layers, link 
layers, etc.  If I have an abstract MAC_layer interface, it helps me 
think carefully about what every MAC layer ought to provide, and it also 
helps me explain to other people what a MAC layer in my simulator must 
provide.  That is, it helps me better explain to other people how the 
system's major components relate to each other.


Now, I could use Java or C# to get functionality such as interfaces, but 
I loath giving up the general productive goodness of Python.  That's why 
I'm looking for something like interfaces.

But even if we disagree about the wisdom of my intentions, do you know 
if/when Guido's planning to work that stuff into Python?  The last post 
I noticed from him on the topic was from 2005.  At least back then he 
sounded pretty into it.

Thanks,
Christian

Bruno Desthuilliers wrote:
> Christian Convey a écrit :
>> Hi guys,
>>
>> I'm looking at developing a somewhat complex system, and I think some 
>> static typing will help me keep limit my confusion.  
> 
> Then I think you're suffering from an alas too common delusion. Static 
> typing (at least declarative static typing) will only makes your system 
> more complex. But if you want some help in managing complexity, you may 
> want to look at interfaces systems (Zope3 interfaces or Peak's Protocol) 
> and multidispatch (Peak's Protocol dispatch package).
> 

-- 
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Anonymous dynamic import

2006-08-28 Thread Christian Convey
Anyone know how to do this?:I want a way to dynamically import modules (module names not known until runtime).  I want to end up with a handle to the resulting module object, without having poluted my global module namespace in the process.
Basically I want to something like this:def  call_all_user_supplied_foo_functions(user_script_pathanmes):   for f in user_script_pathanmes:  a_module = magic_module_import_function(f)  a_module.foo()
Any ideas?I've looked at using imp.load_source() or imp.load_module(), but it looks to me like all of these polute the global namespace with the names of the modules I'm importing.Thanks,Christian

-- 
http://mail.python.org/mailman/listinfo/python-list

Python 2.4/2.5 hang on bad reference?

2006-12-28 Thread Christian Convey
Has anyone seen the following?

I've got a somewhat complicated program that includes pygtk, some C/C++ 
code, and lots of Python code.

My problem is that when some code tries to use a global variable that 
hasn't yet been created, or tries to invoke a method/function that 
doesn't exist in another module, the entire python program hangs. Ctrl-C 
doesn't kill it; I need to whack it from another terminal using the kill 
command.

Using print statements, it basically looks like execution of the Python 
interpreter simply hangs when it goes to the problem statement.

The code involved is straight, single-threaded Python code.  The code is 
running on the Gtk's event-handling thread.


I'm using a clean install of Ubuntu 6.10, and I see the same problem in 
both 2.4 and 2.5.

I've tried wrapping the offending code with a try/catch block, so that 
in case there's an exception it will get printed to stdout, but as far 
as I can tell my exception handler is never getting invoked.  (Perhaps 
I'm accidentally crafting my "except" statements too narrowly?)

Any ideas?

Thanks very much,
Christian

-- 
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


numpy, numarray, or numeric?

2007-02-15 Thread Christian Convey
I need to bang out an image processing library (it's schoolwork, so I
can't just use an existing one).  But I see three libraries competing
for my love: numpy, numarray, and numeric.

Can anyone recommend which one I should use?  If one is considered the
officially blessed one going forward, that would be my ideal.

Thanks,
Christian
-- 
http://mail.python.org/mailman/listinfo/python-list