line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Coro::ProcessPool::Worker; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$Coro::ProcessPool::Worker::VERSION = '0.28'; |
4
|
1
|
|
|
1
|
|
78256
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
8
|
use Coro; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
7
|
1
|
|
|
1
|
|
269
|
use Coro::Handle qw(unblock); |
|
1
|
|
|
|
|
23359
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
286
|
use Coro::ProcessPool::Util qw($EOL decode encode); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
99
|
|
9
|
1
|
|
|
1
|
|
228
|
use Module::Load qw(load); |
|
1
|
|
|
|
|
801
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
316
|
use Devel::StackTrace; |
|
1
|
|
|
|
|
2927
|
|
|
1
|
|
|
|
|
272
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub run { |
13
|
0
|
|
|
0
|
0
|
0
|
my $in = unblock *STDIN; |
14
|
0
|
|
|
|
|
0
|
my $out = unblock *STDOUT; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
$out->print($$ . $EOL); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
while (my $line = $in->readline($EOL)) { |
19
|
0
|
|
|
|
|
0
|
my ($id, $task, $args) = decode($line); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
0
|
if ($task eq 'self-terminate') { |
22
|
0
|
|
|
|
|
0
|
last; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
my ($error, $result) = process_task($task, $args); |
26
|
0
|
|
|
|
|
0
|
$out->print(encode($id, $error, $result) . $EOL); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$in->shutdown; |
30
|
0
|
|
|
|
|
0
|
$out->shutdown; |
31
|
0
|
|
|
|
|
0
|
exit 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub process_task { |
35
|
3
|
|
|
3
|
0
|
3449
|
my ($task, $args) = @_; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
4
|
my $result = eval { |
38
|
3
|
100
|
66
|
|
|
15
|
if (ref $task && ref $task eq 'CODE') { |
39
|
2
|
|
|
|
|
5
|
$task->(@$args); |
40
|
|
|
|
|
|
|
} else { |
41
|
1
|
|
|
|
|
5
|
load $task; |
42
|
1
|
50
|
|
|
|
413
|
die "method new() not found for class $task" unless $task->can('new'); |
43
|
1
|
50
|
|
|
|
4
|
die "method run() not found for class $task" unless $task->can('run'); |
44
|
1
|
|
|
|
|
3
|
my $obj = $task->new(@$args); |
45
|
1
|
|
|
|
|
7
|
$obj->run; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
3
|
100
|
|
|
|
32
|
if ($@) { |
50
|
1
|
|
|
|
|
2
|
my $error = $@; |
51
|
1
|
|
|
|
|
8
|
my $trace = Devel::StackTrace->new( |
52
|
|
|
|
|
|
|
message => $error, |
53
|
|
|
|
|
|
|
indent => 1, |
54
|
|
|
|
|
|
|
ignore_class => ['Coro::ProcessPool::Util', 'Coro', 'AnyEvent'], |
55
|
|
|
|
|
|
|
); |
56
|
1
|
|
|
|
|
253
|
return (1, $trace->as_string); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
6
|
return (0, $result); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Coro::ProcessPool::Worker - Run loop for worker process |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 0.28 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Jeff Ober <sysread@fastmail.fm> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Jeff Ober. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
87
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|