MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / set_worker_pids

Function set_worker_pids

imperative/python/src/utils.cpp:267–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267static void set_worker_pids(PyObject* id, PyObject* tuple_item) {
268 int64_t key = unpackLong(id);
269 if (worker_pids.find(key) != worker_pids.end()) {
270 throw std::runtime_error(
271 "_set_worker_pids should be called only once for each "
272 "DataLoaderIter.");
273 }
274
275 if (!PyTuple_Check(tuple_item)) {
276 throw std::runtime_error("_set_worker_pids expects a tuple for child_pids");
277 }
278
279 std::set<pid_t> pids_set = {};
280 auto size = PyTuple_GET_SIZE(tuple_item);
281 for (Py_ssize_t idx = 0; idx < size; ++idx) {
282 PyObject* obj = PyTuple_GET_ITEM(tuple_item, idx);
283 pids_set.insert(static_cast<pid_t>(unpackLong(obj)));
284 }
285
286 worker_pids[key] = pids_set;
287}
288
289static void reset_worker_pids(PyObject* loader_id) {
290 int64_t key = unpackLong(loader_id);

Callers 1

init_utilsFunction · 0.85

Calls 4

unpackLongFunction · 0.85
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected