0

I have a python file like my_functions.py and within that file is a function

def func(a,b):
      result = does_some_stuff(a,b)
      return result

Is there a bash one-liner that would open N python sessions and run this function with specified arguments a and b? I'm thinking of using this for some poor man's parallel processing, since there's some randomness in func all the calls wouldn't do the same thing even with the same arguments a and b.

1 Answer 1

1

First if bash must run the python script with arguments and execute the function func, you need to add a __main__ section at the end of your .py file, for example:

if __name__ == "__main__":
    import sys
    func(sys.argv[1], sys.argv[2])

You may want to print the result of func to stdout, use it as the script exit code, ...

Then a bash script can just execute "python myfunc.py 12 42 &" to run the function. "&" means that the program runs in the background.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .