Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87791
| References | <b6be91a9-8f65-4136-bd03-af7013e0915b@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2015-03-20 12:19 -0600 |
| Subject | Re: Threading: execute a callback function in the parent thread |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.44.1426875639.10327.python-list@python.org> (permalink) |
On Fri, Mar 20, 2015 at 11:29 AM, <massi_srb@msn.com> wrote: > Hi everyone, > > just like the title says I'm searching for a mechanism which allows to call a callback function from a thread, being the callback executed in the parent thread (it can also be the main thread). I'm basically looking for something like the CallAfter method of the wx or the signal slot mechanism of the pyqt. Is there something similar but made only in native python? any workaround is welcome. There's no general way to tell another thread to execute something, because that thread is *already* executing something -- you can't just interrupt it and say "here, do this instead". There has to be some mechanism in place for scheduling the thing to be executed. You can do this with the main thread of frameworks like wx because the main thread in that case is running an event loop which enables the callback to be scheduled. If your target thread is not running an event loop or being used as an executor (either of which should provide a specific API for this), then you will need to have that thread explicitly checking a callback queue from time to time to see if there's anything ready for it to call.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Threading: execute a callback function in the parent thread massi_srb@msn.com - 2015-03-20 10:29 -0700 Re: Threading: execute a callback function in the parent thread Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-20 12:19 -0600
csiph-web