multithreading - Python child thread to communicate the caller via event -


related: catch thread's exception in caller thread in python

when catch exception in child thread:
need let thread caller know

in related posting, accepted answer checks queue fine prevents main caller doing else because keep checking queue

so ideal if it's event based.

the solution should be: main caller things (not continuously checking queue error in child thread) , if goes bad inside child thread, child thread lets main caller know through event , main caller process error.

i ve been looking @ different articles , solutions event stuff directed towards main caller communicating child thread , not vice versa

any solution child thread communicating caller via events?

there no such thing "thread caller". threads equal.

in head "main thread" special because python gives free far python concerned, main thread tread other.

so question boils down to: how can exchange information between 2 threads?

with 1 or more queues.

usually, pseudo code looks this:

  1. create n workers, connected input , output queue.
  2. put work input queue
  3. wait results on output queue
  4. join threads

note don't have block in step #3. can ask queue whether has elements. if so, get() won't block. if it's empty, can other things.

step #4 more simple implement, when define "kill" command threads respond "i'm done" reply.

you can send n kill commands , wait n replies. afterwards, can sure threads done.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -