Start new process by function ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Sakkis

    #1

    Start new process by function ?

    Is it possible to start a new process by specifying a function call (in similar function to thread
    targets) instead of having to write the function in a separate script and call it through os.system
    or os.spawn* ? That is, something like

    def foo(): pass
    os.spawn(foo)

    Thanks in advance,

    George


    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~
    Haiku of the day:

    "A file that big? / It might be very useful / But now it is gone. "
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~


  • Mathias Waack

    #2
    Re: Start new process by function ?

    George Sakkis wrote:
    [color=blue]
    > Is it possible to start a new process by specifying a function call
    > (in similar function to thread targets) instead of having to write
    > the function in a separate script and call it through os.system or
    > os.spawn* ? That is, something like
    >
    > def foo(): pass
    > os.spawn(foo)[/color]

    Just starting is easy:

    def spawn(f):
    if os.fork() == 0:
    f()
    sys.exit(0)

    But I'd expect you would like to get some return values from f...

    Mathias

    Comment

    Working...