open() with pipe breaks AnyEvent STDIN poll
Marc Lehmann
schmorp at schmorp.de
Wed Nov 26 18:16:57 CET 2014
On Thu, Nov 27, 2014 at 12:15:20AM +1100, Nick Andrew <nick at nick-andrew.net> wrote:
> Ok. I wasn't aware that $_ is a global variable; it didn't even enter my
> thinking as you can see; I thought the problem was with file handles and
> STDIN; the while (<FH>) loop didn't even occur to me as the source of
> the problem.
Together with "for" localising but "while" not - one of the vestiges of
perl that we all love, no? :)
In any case, thats the motivation behind AnyEvent::Strict.
> Would it be reasonable for AnyEvent to change to not use $_ within
> the event loop, to prevent a whole class of problems and protect its
> own data structures?
Since more classes of problems (including this one) are diagnosed by
AnyEvent::Strict, I think not.
Remember, in this case, it found a bug in another library - AnyEvent does
localise $_ so other software doesn't have this problem with AnyEvent, the
problem here is the other software modifying it without localising it, and
AnyEvent is just the victim.
So if anyevent localised it even more (at a speed hit), it would protect
itself, but other code will still run into the same problem. For example, if
you used a while(<>) loop and called the third party code, or if you used a
for loop and calling that 3rd-party code, you'd still stumble over this
problem.
I think its better to catch this bug instead of working around it silently
and letting the next one fall into the trap. This also allows you to chose
between strict (and slow) mode and non-strict (but fast) mode.
In the end, it's a philosophical thing - I think its better to fix a
bug in a program than to silently work around it in every other program
and let new users fall into the trap - especially when there is a tool that
will detect this problem in 100% of the cases (AnyEvent::Strict).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list