[Python-ideas] @run_as_thread decorator
geremy condra
debatem1 at gmail.com
Sat Mar 5 18:48:55 CET 2011
On Sat, Mar 5, 2011 at 9:16 AM, Jesse Noller <jnoller at gmail.com> wrote:
> 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
I've personally written this about five times. Having said that, what
I'd really like would be a context manager that executed the contained
block of code in a new thread or process, and I haven't gotten that to
work the way I'd like so far.
Geremy Condra
More information about the Python-ideas
mailing list