non-blocking http call and glib

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

non-blocking http call and glib

haratron
I'm trying to do a non blocking call to an http server with Mojo::UserAgent so that it doesn't block the Gtk GUI while it's waiting for the response. I want to do the request and once the results are back to update the GUI. I'm confused on how to do this. I'm on win32, here's the code so far. 


This code makes the program hang and they told me on #perl that it's because I'm using two loops, one from Gtk and one from Mojo. 
What is the correct way of doing this?


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: non-blocking http call and glib

Grant McLean
You might want to look at libsoup - the Gnome library for HTTP requests.
I think the latest Perl bindings are here:

  https://metacpan.org/release/HTTP-Soup-Gnome

Regards
Grant

On Sun, 2017-02-26 at 23:41 +0200, haratron wrote:

> I'm trying to do a non blocking call to an http server with
> Mojo::UserAgent so that it doesn't block the Gtk GUI while it's
> waiting for the response. I want to do the request and once the
> results are back to update the GUI. I'm confused on how to do this.
> I'm on win32, here's the code so far.
>
>
> http://pastebin.ca/3772676
>
>
> This code makes the program hang and they told me on #perl that it's
> because I'm using two loops, one from Gtk and one from Mojo.
> What is the correct way of doing this?
>
>
> _______________________________________________
> gtk-perl-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: non-blocking http call and glib

haratron
Can anyone try this code and post if there's any output? I don't get any output. I suspect something is wrong on the lib level.
 
I'm on Windows 10 with Strawberry Perl 5.24 64bit btw.

======

#!/usr/bin/perl

use strict;
use warnings;

use IO::Async::Loop::Glib;
use Net::Async::HTTP;
use Gtk2 qw( -init );

my $loop = IO::Async::Loop::Glib->new;

my $ua = Net::Async::HTTP->new;
$loop->add( $ua );

recognition();

Gtk2->main;



sub recognition
{
   my $f = $ua->POST(
      [
         test => "params",
         go => "here",
      ]
   )->then(
      # success
      sub {
         my ( $response ) = @_;

         print "response is: $response\n";
         Future->done;
      },

      # failure
      sub {
         my ( $error ) = @_;

         print "failure is $error\n";
         Future->done;
      },
   );

   $ua->adopt_future( $f );
}

On Mon, Feb 27, 2017 at 12:04 AM, Grant McLean <[hidden email]> wrote:
You might want to look at libsoup - the Gnome library for HTTP requests.
I think the latest Perl bindings are here:

  https://metacpan.org/release/HTTP-Soup-Gnome

Regards
Grant

On Sun, 2017-02-26 at 23:41 +0200, haratron wrote:
> I'm trying to do a non blocking call to an http server with
> Mojo::UserAgent so that it doesn't block the Gtk GUI while it's
> waiting for the response. I want to do the request and once the
> results are back to update the GUI. I'm confused on how to do this.
> I'm on win32, here's the code so far.
>
>
> http://pastebin.ca/3772676
>
>
> This code makes the program hang and they told me on #perl that it's
> because I'm using two loops, one from Gtk and one from Mojo.
> What is the correct way of doing this?
>
>
> _______________________________________________
> gtk-perl-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: non-blocking http call and glib

haratron
Thanks Shawn, that should be it.
The tests didn't pass, but I skipped it with notest install. 
I guess I need to find another way to do it.


On Mon, Feb 27, 2017 at 4:24 AM, Shawn Laffan <[hidden email]> wrote:
The test suite for IO::Async::Loop::Glib hangs on my machine when I try to install it (also Strawberry Perl 5.24.1 x64).

There is already a ticket open for it.  https://rt.cpan.org/Public/Bug/Display.html?id=116582

Did the tests pass on your machine when installing?

Shawn.


On 27 February 2017 at 12:51, haratron <[hidden email]> wrote:
Can anyone try this code and post if there's any output? I don't get any output. I suspect something is wrong on the lib level.
 
I'm on Windows 10 with Strawberry Perl 5.24 64bit btw.

======

#!/usr/bin/perl

use strict;
use warnings;

use IO::Async::Loop::Glib;
use Net::Async::HTTP;
use Gtk2 qw( -init );

my $loop = IO::Async::Loop::Glib->new;

my $ua = Net::Async::HTTP->new;
$loop->add( $ua );

recognition();

Gtk2->main;



sub recognition
{
   my $f = $ua->POST(
      [
         test => "params",
         go => "here",
      ]
   )->then(
      # success
      sub {
         my ( $response ) = @_;

         print "response is: $response\n";
         Future->done;
      },

      # failure
      sub {
         my ( $error ) = @_;

         print "failure is $error\n";
         Future->done;
      },
   );

   $ua->adopt_future( $f );
}

On Mon, Feb 27, 2017 at 12:04 AM, Grant McLean <[hidden email]> wrote:
You might want to look at libsoup - the Gnome library for HTTP requests.
I think the latest Perl bindings are here:

  https://metacpan.org/release/HTTP-Soup-Gnome

Regards
Grant

On Sun, 2017-02-26 at 23:41 +0200, haratron wrote:
> I'm trying to do a non blocking call to an http server with
> Mojo::UserAgent so that it doesn't block the Gtk GUI while it's
> waiting for the response. I want to do the request and once the
> results are back to update the GUI. I'm confused on how to do this.
> I'm on win32, here's the code so far.
>
>
> http://pastebin.ca/3772676
>
>
> This code makes the program hang and they told me on #perl that it's
> because I'm using two loops, one from Gtk and one from Mojo.
> What is the correct way of doing this?
>
>
> _______________________________________________
> gtk-perl-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list




_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: non-blocking http call and glib

Juergen Harms
I have had very positive experience with solving this kind of problem by
making the utility that blocks run in its own process (perl fork with
open2 or open3) and not using gtk, resp. a main loop (in that process).
This is a step down in the level of programming tools, but the extra
effort is quite limited (you need some amount of additional coding for
implementing synchronisation) - and worth while to consider if you dont
find a boxed solution.

Juergen
_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Loading...