aaronmarkham commented on a change in pull request #13647: Update lip reading 
example
URL: https://github.com/apache/incubator-mxnet/pull/13647#discussion_r244111396
 
 

 ##########
 File path: example/gluon/lipnet/utils/multi.py
 ##########
 @@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Module: preprocess with multi-process
+"""
+
+
+def multi_p_run(tot_num, _func, worker, params, n_process):
+    """
+    Run _func with multi-process using params.
+    """
+    from multiprocessing import Process, Queue
+    out_q = Queue()
+    procs = []
+
+    split_num = split_seq(list(range(0, tot_num)), n_process)
+
+    print(tot_num, ">>", split_num)
+
+    split_len = len(split_num)
+    if n_process > split_len:
+        n_process = split_len
+
+    for i in range(n_process):
+        _p = Process(target=_func,
+                     args=(worker, split_num[i][0], split_num[i][1],
+                           params, out_q))
+        _p.daemon = True
+        procs.append(_p)
+        _p.start()
+
+    try:
+        result = []
+        for i in range(n_process):
+            result.append(out_q.get())
+        for i in procs:
+            i.join()
+    except KeyboardInterrupt:
+        print('Killing all the childer in the pool.')
+        for i in procs:
+            i.terminate()
+            i.join()
+        return -1
+
+    while not out_q.empty():
+        print(out_q.get(block=False))
+
+    return result
+
+
+def split_seq(sam_num, n_tile):
+    """
+    Spli the number(sam_num) into numbers by n_tile
 
 Review comment:
   ```suggestion
       Split the number(sam_num) into numbers by n_tile
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to