in reply to Re: Coro, EV and cede
in thread Coro, EV and cede

use strict; use warnings; use Coro; use Coro::EV; use Coro::LWP; use LWP::Simple; use Coro::Timer qw(sleep); async { while (1) { CORE::select undef, undef, undef, 0.5; print "first\n"; # my $r = get "http://www.perlmonks.org"; # print length $r, "\n"; # sleep 0; cede; } }; async { while (1) { CORE::select undef, undef, undef, 0.5; print "second\n"; # sleep 0; cede; } }; EV::loop while 1;
output:
first second first second first second ...
When uncomment
my $r = get "http://www.perlmonks.org"; print length $r, "\n";
got output:
first second second second second second second second
Then uncomment "sleep 0" and got output :
first second 76573 second first second 76570 second first second 76597 second first second

Replies are listed 'Best First'.
Re^3: Coro, EV and cede
by Corion (Patriarch) on Apr 07, 2011 at 12:12 UTC

    Depending on your version of LWP, LWP::Simple might or might not play nice with LWP::Coro. I know that at least for some versions prior to 5.827, LWP::Simple used its own socket factory instead of using what LWP::UserAgent did.

    You might want to inspect your module versions.

    Be careful when upgrading to LWP 6.x. If you use HTTPS connections, you will at least also need to install Mozilla::UA, because LWP 6 checks the validity of https certificates.

      No, I've checked at once - it doesn't depend on LWP.

      The same is going on with any EV-based module. For example, with AnyEvent::HTTP or with just EV.

Re^3: Coro, EV and cede
by zwon (Abbot) on Apr 07, 2011 at 13:00 UTC

    The first result shows that cede works, as you get your switching. The problem starts after LWP comes in, and looking into Coro::LWP documentation, it looks like it does something rather cumbersome. I don't see it even tries to establish connection with the server. But if I replace CORE::select with just select everything is ok.

    I'd say you should try something else. I had positive experience with AnyEvent::HTTP, or maybe threads.

      CORE::select is used to slow down the output. Its change to Coro select is equal to the call of Coro sleep 0. Remove the select at all if you wish.

      The problem will still persist with using AnyEvent::HTTP.

        Yes, sorry, I wasn't clear, I meant "no Coro at all" when suggested AnyEvent::HTTP.