[Python-ideas] @run_as_thread decorator
Jesse Noller
jnoller at gmail.com
Sat Mar 5 18:16:40 CET 2011
On Sat, Mar 5, 2011 at 8:21 AM, Giampaolo Rodolà <g.rodola at gmail.com> wrote:
> >>> import time, threading
> >>>
> >>> @threading.run_as_thread
> ... def foo():
> ... time.sleep(100)
> ... return 1
> ...
> >>> t = foo()
> >>> t.isAlive()
> True
> >>> t.join()
> >>> t.isAlive()
> False
> >>>
>
> The same thing could be done for multiprocessing module.
> Would this be acceptable for inclusion?
>
>
I've long wanted to put something into the stdlib like this, but as
others in the thread have pointed out - there's some semantics that
remain to be hashed out and the behavior is dangerous (imo), and
magical to have in the stdlib right now.
In this case, I would recommend building out a library that contains
these decorators (both threads and processes) building from the
futures (concurrent.futures.Executor ABC) library as possible, and
let's see how it pans out. I've struggled with really liking/wanting
this and the fact that it's dangerous, and surprising.
jesse
More information about the Python-ideas
mailing list