core.thread_utils

Provides utilities useful for multiprocessing.

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

Bases: collections.abc.MutableMapping

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
__init__(init_dict=None)

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.