def run(function, *args, use_subprocess=False, daemon=True, **kwds):
if use_subprocess:<EOL><INDENT>Creator, Queue = multiprocessing.Process, multiprocessing.Queue<EOL><DEDENT>else:<EOL><INDENT>Creator, Queue = threading.Thread, queue.Queue<EOL><DEDENT>input, output = Queue(), Queue()<EOL>args = input, output, function, args<EOL>sub = Creator(target=_run_locally, args=args, kwargs=kwds, daemon=daemon)<EOL>sub.start()<EOL>return sub, input, output<EOL>
Create input, output queues, call `function` in a subprocess or a thread.

``function`` is called like this: ``function(input, output, *args, **kwds)``

:param use_subprocess: if true, create a new multiprocess;
                       if false, create a new thread
:param function: the function to call
:param daemon: is the thread or subprocess run as a daemon or not?

:param args: positional arguments to the function
:param kwds: keyword arguments to the function
:returns: a tuple with three elements: the subprocess or thread, an input
          queue, and an output queue.