Dictionary inserts and threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin P. Hellwig

    #1

    Dictionary inserts and threads

    Hi all,

    I'm thinking to speed up a process, I like to use multiple threads to
    get data fractions from multiple servers and place those data fragments
    into a local dictionary for further processing, the dictionary will look
    like this:

    self.dic = {'thread_a':dic t(),
    'thread_b':dict ()}

    The fragments will not overlap each other, since they will be
    subdictionaries within the dictionary, though it would be possible that
    multiple threads do something like this at the same time:

    self.dic['thread_a'] = data_from_a()
    and
    self.dic['thread_b'] = data_from_b()

    I assume that this is not a problem, but since assuming something gives
    a lot of room for screw-ups I rather ask beforehand if I should except
    all kinds of troubles when multiple threads update 'at the same time' a
    dictionary or that I should lock the dictionary, for each update?

    Thanks for your insights.

    --
    mph

  • Paul Rubin

    #2
    Re: Dictionary inserts and threads

    "Martin P. Hellwig" <mhellwig@xs4al l.nlwrites:
    I assume that this is not a problem, but since assuming something
    gives a lot of room for screw-ups I rather ask beforehand if I should
    except all kinds of troubles when multiple threads update 'at the same
    time' a dictionary or that I should lock the dictionary, for each
    update?
    Use a lock, or serialize the updates through a queue.

    Comment

    Working...