Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[FR] prun -- OMUD
02-15-2018, 01:10 PM (This post was last modified: 06-22-2018 10:37 AM by rayluk.)
Post: #1
[FR] prun -- OMUD
[FR] Use python to implement prun ( http://tab.d-thinker.org/showthread.php?...http://tab.d-thinker.org/showthread.php?tid=10781&pid=7602 )

Driving example: generalize the parallel running logic in dexer

This is a function that helps to run a sequence of command in parallel

User Info
First, source /thinker/local/forest/util/utilib/prun
then, you can use the function prun
prun [ --no-error ] <cmds>
--no-error: if --no-error is specified, the return code will always be zero
<cmds>: commands to be run. Should be in form of a bash array of strings where each string is one command There should be at least 1 command.

Example
Code:
source /thinker/local/forest/util/utilib/prun
declare -a arr=("ls -alh" "sleep 1")
prun arr[@]

Maintainer's Info
cod://utilib/prun

Designer's Info
Code:
no_error=False
if --no-error is specified
    no_error=True

pid_array=""
for $cmd in $arg_array
   run $cmd & append $! to $pid_array

failcount=0
for $pid in $pid_array:
   wait $pid && rr=$?
   if rr != 0:
       $failcount++
if no_error
   return 0
else
   return $failcount
Find all posts by this user
Quote this message in a reply
02-15-2018, 01:11 PM
Post: #2
RE: prun -- OMUD
@zma
please review the headpost
Find all posts by this user
Quote this message in a reply
02-15-2018, 01:26 PM
Post: #3
RE: prun -- OMUD
A library function will be better. function calls can be supported and the environment of caller is shared to the callees.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-15-2018, 02:00 PM
Post: #4
RE: prun -- OMUD
Save a copy

(02-15-2018 01:10 PM)rayluk Wrote:  Driving example: generalize the parallel running logic in dexer

This is a command that helps to run a sequence of command in parallel

User Info
prun [ --no-error ] <cmd> [ <cmd>, ...]
--no-error: if --no-error is specified, the return code will always be zero
<cmd>: command to be run. There should be at least 1 command.

Maintainer's Info
cod://bin/prun

Designer's Info
Code:
no_error=False
if --no-error is specified
    no_error=True

pid_array=""
for $cmd in $arg_array[1:]
   run $cmd & append $! to $pid_array

failcount=0
for $pid in $pid_array:
   wait $pid && rr=$?
   if rr != 0:
       $failcount++
if no_error
   return 0
else
   return $failcount
Find all posts by this user
Quote this message in a reply
02-15-2018, 02:05 PM
Post: #5
RE: prun -- OMUD
@zma,

The headpost's overview ,user info and maintainers info is updated.

Changes:
Moving it to utilib as it is not a command for running.
Changed it to a bash function.
Find all posts by this user
Quote this message in a reply
02-15-2018, 02:09 PM
Post: #6
RE: prun -- OMUD
(02-15-2018 01:10 PM)rayluk Wrote:  Driving example: generalize the parallel running logic in dexer

This is a function that helps to run a sequence of command in parallel

User Info
First, source /thinker/local/forest/util/utilib/prun
then, you can use the function prun
prun [ --no-error ] <cmds>
--no-error: if --no-error is specified, the return code will always be zero
<cmds>: commands to be run. Should be in form of a bash array of strings where each string is one command There should be at least 1 command.

Example
Code:
source /thinker/local/forest/util/utilib/prun
declare -a arr=("ls -alh" "sleep 1")
prun arr[@]

Maintainer's Info
cod://utilib/prun

Designer's Info
Code:
no_error=False
if --no-error is specified
    no_error=True

pid_array=""
for $cmd in $arg_array[1:]
   run $cmd & append $! to $pid_array

failcount=0
for $pid in $pid_array:
   wait $pid && rr=$?
   if rr != 0:
       $failcount++
if no_error
   return 0
else
   return $failcount

LGTM.

Please make sure `for $cmd in $arg_array[1:]` works as expected. If needed, you may pass an array length argument too.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-19-2018, 04:51 PM (This post was last modified: 02-19-2018 04:51 PM by rayluk.)
Post: #7
RE: prun -- OMUD
(02-15-2018 02:09 PM)zma Wrote:  
(02-15-2018 01:10 PM)rayluk Wrote:  Driving example: generalize the parallel running logic in dexer

This is a function that helps to run a sequence of command in parallel

User Info
First, source /thinker/local/forest/util/utilib/prun
then, you can use the function prun
prun [ --no-error ] <cmds>
--no-error: if --no-error is specified, the return code will always be zero
<cmds>: commands to be run. Should be in form of a bash array of strings where each string is one command There should be at least 1 command.

Example
Code:
source /thinker/local/forest/util/utilib/prun
declare -a arr=("ls -alh" "sleep 1")
prun arr[@]

Maintainer's Info
cod://utilib/prun

Designer's Info
Code:
no_error=False
if --no-error is specified
    no_error=True

pid_array=""
for $cmd in $arg_array[1:]
   run $cmd & append $! to $pid_array

failcount=0
for $pid in $pid_array:
   wait $pid && rr=$?
   if rr != 0:
       $failcount++
if no_error
   return 0
else
   return $failcount

LGTM.

Please make sure `for $cmd in $arg_array[1:]` works as expected. If needed, you may pass an array length argument too.

We don't have to pass a length argument but the range description here is wrong, we should be using the whole array.


Implemented in commit 9888801fb7f50aaf1c0dfd077e44ae97f374ac85
Find all posts by this user
Quote this message in a reply
02-20-2018, 10:20 AM
Post: #8
RE: prun -- OMUD
@Xinjie,

this is the tool that is created for generalizing the parallel running feature in dexer. This would fits the usage of dexer. Please let me know if it doesn't fit the usage of wait_errexit .
Find all posts by this user
Quote this message in a reply
06-21-2018, 07:30 PM (This post was last modified: 06-21-2018 07:41 PM by lingu.)
Post: #9
RE: prun -- OMUD
Why didn't you fix/improve dexer? Why create a new tool?

If you want a general prun function to be used by multiple programs, use Python to program it.
Find all posts by this user
Quote this message in a reply
06-22-2018, 10:36 AM
Post: #10
RE: prun -- OMUD
(06-21-2018 07:30 PM)lingu Wrote:  Why didn't you fix/improve dexer? Why create a new tool?

Becasue we need a library for other tools ( http://tab.d-thinker.org/showthread.php?...http://tab.d-thinker.org/showthread.php?tid=5225&pid=6498 )


(06-21-2018 07:30 PM)lingu Wrote:  If you want a general prun function to be used by multiple programs, use Python to program it.

I will make this a FR
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: