Monday, December 17, 2012

.... and one more for Python vs. Perl


Python:

def command_wrapper(args):
    <some logic>

pool = multiprocessing.Pool(pool_size)
try:
  pool.map_async(command_wrapper, commands).get(run_timeout)
except SomeTimeOutException:
  <some timeout handler>


Perl:

while ($children < $max_children) {
  if (my $pid = fork) {
    $children++;
  } else {
    $SIG{'ALRM'} = sub {
     <some sig_alrm handler>
    }
    alarm(run_timeout);
    <some logic>
    $SIG{'ALRM'} = 'DEFAULT';
  }
}

No comments:

Post a Comment