Skip to content Skip to sidebar Skip to footer

Control The Value Returned By A Spawned Process

In the code below, the worker function checks if the data passed is valid and if it is valid, it returns a dictionary which will be used in a bulk SQLAlchemy Core insert. If its in

Solution 1:

You can just remove the None entries from the list:

received_list = filter(None, p.map(process_data, data_to_process))

This is pretty quick even for really huge lists:

>>>timeit.timeit('l = filter(None, l)', 'l = range(0,10000000)', number=1)
0.47683095932006836

Note that using filter will remove anything where bool(val) is False, like empty strings, empty lists, etc. This should be fine for your use-case, though.

Post a Comment for "Control The Value Returned By A Spawned Process"