Threaded asynchronous return from functions
Short version: Could we get def funct( args ): if args == 'good': return 'good' async_return "I'll think about it" if args == '123': do_x() elif args == 'abc': do_y() else: do_z() as equivalent to def do_thinking( args ): if args == '123': do_x() elif args == 'abc': do_y() else: do_z() def funct( args ): if args == 'good': return 'good' t = threading.Thread(target=do_thinking, args=args) t.start() return "I'll think about it" Longer version: I have been doing some multithreaded work lately and have found that often what I find wanting to do is to call a function, have it check it's arguments, possibly do some work and then return to the caller, but still do some extra processing right after that. Currently to accomplish such feat I need to separate the 'extra processing' bit into a separate function and call that in a separate thread. A nice convenience would be a function or statement that would allow to return a value from the current function, but still keep running its code (in a separate thread). Such approach could then be used in many places where async processing is required, such as GUI programming, XMLRPC, web applications, ... with less boilerplate and more obvious code flow. -- Best regards, Aigars Mahinovs mailto:aigarius@debian.org #--------------------------------------------------------------# | .''`. Debian GNU/Linux (http://www.debian.org) | | : :' : Latvian Open Source Assoc. (http://www.laka.lv) | | `. `' Linux Administration and Free Software Consulting | | `- (http://www.aiteki.com) | #--------------------------------------------------------------#
Hello, 2011/7/4 Aigars Mahinovs <aigarius@gmail.com>
I have been doing some multithreaded work lately and have found that
often what I find wanting to do is to call a function, have it check
it's arguments, possibly do some work and then return to the caller, but still do some extra processing right after that. Currently to accomplish such feat I need to separate the 'extra processing' bit into a separate function and call that in a separate thread. A nice convenience would be a function or statement that would allow to return a value from the current function, but still keep running its code (in a separate thread). Such approach could then be used in many places where async processing is required, such as GUI programming, XMLRPC, web applications, ... with less boilerplate and more obvious code flow.
This kind of topic is not suitable to python-dev. Please ask this on the python-list mailing list, or eventually on python-ideas. (where someone will probably suggest you to use a nested function) Cheers, -- Amaury Forgeot d'Arc
participants (2)
-
Aigars Mahinovs -
Amaury Forgeot d'Arc