parameters: (f, args, kwds, callback)
docstring: Run f in a forked subprocess with given args and kwds, then call the
      callback function when f terminates.
docstring_summary: Run f in a forked subprocess with given args and kwds, then call the
      callback function when f terminates.
docstring_tokens: Run f in a forked subprocess with given args and kwds then call the callback function when f terminates .
function: def async(f, args, kwds, callback):
      """
      Run f in a forked subprocess with given args and kwds, then call the
      callback function when f terminates.
      """
      from sage.misc.all import tmp_filename
      filename = tmp_filename() + '.sobj'
      sys.stdout.flush()
      sys.stderr.flush()
      pid = os.fork()
      if pid:
          # The parent master process
          try:
              _wait_in_thread(pid, callback, filename)
              return pid
          finally:
              if os.path.exists(filename):
                  os.unlink(filename)
      else:
          # The child process
          try:
              result = f(*args, **kwds)
          except Exception, msg:
              result = str(msg)
          from sage.structure.sage_object import save
          save(result, filename)
          os._exit(0)
function_tokens: def async ( f , args , kwds , callback ) : from sage . misc . all import tmp_filename filename = tmp_filename ( ) + '.sobj' sys . stdout . flush ( ) sys . stderr . flush ( ) pid = os . fork ( ) if pid : # The parent master process try : _wait_in_thread ( pid , callback , filename ) return pid finally : if os . path . exists ( filename ) : os . unlink ( filename ) else : # The child process try : result = f ( * args , * * kwds ) except Exception , msg : result = str ( msg ) from sage . structure . sage_object import save save ( result , filename ) os . _exit ( 0 )