MCPcopy Create free account
hub / github.com/C3ting/ARL / ThreadMap

Class ThreadMap

app/services/baseThread.py:66–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65
66class ThreadMap(BaseThread):
67 def __init__(self, fun, items, arg=None, concurrency=6):
68 super(ThreadMap, self).__init__(targets=items, concurrency=concurrency)
69 if not callable(fun):
70 raise TypeError("fun must be callable.")
71
72 self._arg = arg
73 self._fun = fun
74 self._result_map = {}
75
76 def work(self, item):
77 if self._arg:
78 result = self._fun(item, self._arg)
79 else:
80 result = self._fun(item)
81
82 if result:
83 self._result_map[str(item)] = result
84
85 def run(self):
86 self._run()
87 return self._result_map
88
89
90def thread_map(fun, items, arg=None, concurrency=6):

Callers 1

thread_mapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected