Provides utilities useful for multiprocessing.

class parlai.core.thread_utils.SharedTable(init_dict=None)

Provides a simple shared-memory table of integers, floats, or strings. Use this class as follows:

tbl = SharedTable({'cnt': 0})
with tbl.get_lock():
    tbl['startTime'] = time.time()
for i in range(10):
    with tbl.get_lock():
        tbl['cnt'] += 1

Create a shared memory version of each element of the initial dictionary. Creates an empty array otherwise, which will extend automatically when keys are added.

Each different type (all supported types listed in the types array above) has its own array. For each key we store an index into the appropriate array as well as the type of value stored for that key.


Returns shared value if key is available.

__setitem__(key, value)

If key is in table, update it. Otherwise, extend the array to make room. This uses additive resizing not multiplicative, since the number of keys is not likely to change frequently during a run, so do not abuse it. Raises an error if you try to change the type of the value stored for that key–if you need to do this, you must delete the key first.


Returns simple dict representation of the mapping.


Returns the object type and memory location with the mapping.