Hi tj, I really don't know what could be the issue. Maybe some lock inside
the bach program or something like that.
Anyway, you could try this simple mojo app to see that subprocesses should
not block among them:
#!/usr/bin/env perl
> use Mojolicious::Lite;
>
> get '/:n' => sub {
> my $c = shift;
> $c->inactivity_timeout(180);
> my $n = $c->param('n');
> my $sp = Mojo::IOLoop::Subprocess->new;
> $sp->run(
> sub { `sleep $n` },
> sub {
> my $pid = shift->pid;
> $c->render( text =>
> "Subprocess with pid $pid finished after waiting $n segs\n" );
> }
> );
> };
>
> app->start;
>
>
Just run it with morbo, and then from one browser window go to
http://localhost:3000/30, and from other browser window go for instance to
http://localhost:3000/1, etc
You should be able to run many of them simultaneously, and the pids for
each subprocess should be different.
BR,
El martes, 24 de abril de 2018, 10:49:46 (UTC-3), Caveman Pl escribió:
>
> Hi Daniel,
>
> I found that it works but only once.
>
> When I run batch via web page it is launched an it does its work. And web
> page is working.
> But when I run second batch whens first one is still working web page
> hangs until second one finisz its work.
> Do you know why is that? and how could it be fixed?
>
> Thank you,
>
> tj
>
>
> W dniu niedziela, 22 kwietnia 2018 18:35:34 UTC+2 użytkownik Daniel
> Mantovani napisał:
>
>> Hi tj, I understand that for the run
>> <https://metacpan.org/pod/Mojo::IOLoop::Subprocess#run> method both subs
>> are required. If you don't want to do anything when the batch finish, the
>> second one could be just sub {}
>>
>> i.e.
>>
>>> $subprocess->run(sub { `sh runImportPhen`}, sub {});
>>
>>
>> BR,
>>
>> El sábado, 21 de abril de 2018, 15:46:43 (UTC-3), Caveman Pl escribió:
>>>
>>> Hi group,
>>>
>>>
>>> I just want to run bash script and forget about it.
>>>
>>> I was trying just put it in backgrount with '&' sign
>>> `sh runImportPhen &`;
>>> but it doesn't work.
>>>
>>> Because of it I'm trying with Mojo::IOLoop
>>>
>>> --------Pdataexport.pm----------------------
>>> package MyApp::Pdataexport;
>>>
>>> use base 'Mojolicious::Controller';
>>> use Date::Calc qw(:all);
>>> use File::Path qw(make_path remove_tree);
>>> use Mojo::IOLoop;
>>>
>>>
>>> sub importExternalPhenotypes{
>>>
>>> ...prepare runImportPhen.sh script...
>>>
>>> my $delay = Mojo::IOLoop->delay;
>>> $delay->steps(
>>> sub {
>>> my $delay = shift;
>>> `sh runImportPhen `;
>>> }
>>> );
>>> $self->redirect_to('/pdataexport');
>>> }
>>>
>>> code above also doesn't work. When I click buton which run
>>> importExternalPhenotypes subroutine I need to wait until bash script ends
>>> work - (web page hangs until it finisz)
>>>
>>> I was trying also with
>>>
>>> sub importExternalPhenotypes{
>>>
>>> ...prepare runImportPhen.sh script...
>>>
>>>
>>> my $subprocess = Mojo::IOLoop::Subprocess->new;
>>> $subprocess->run(
>>> sub {
>>> my $subprocess = shift;
>>> `sh runImportPhen `;
>>> }
>>> $self->redirect_to('/pdataexport');
>>> );
>>>
>>>
>>>
>>> but it crash...
>>>
>>> Can you please provide some simple example code how it should be done?
>>>
>>> Thank you,
>>>
>>> tj
>>>
>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.