fork download
  1. import multiprocessing
  2. import time
  3. from opencc import OpenCC
  4.  
  5. class a(object):
  6. def func1(self, i):
  7. return i
  8.  
  9. def test(self, total):
  10. multiprocessing.freeze_support() # for windows, RuntimeError
  11. pool = multiprocessing.Pool(1)
  12.  
  13. startime = time.time()
  14. result = []
  15. for i in range(total):
  16. res = pool.apply_async(self.func1, args=(i,))
  17. result.append(res)
  18.  
  19. pool.close()
  20. self.aa = OpenCC('s2twp')
  21.  
  22. for idx, r in enumerate(result,start=1):
  23. print (r.get())
  24. print('{}/{}'.format(idx, total), end='\r')
  25. print ('')
  26. print ('time=', time.time()-startime)
  27.  
  28. if __name__ == '__main__':
  29. o = a()
  30. o.test(700)
Runtime error #stdin #stdout #stderr 0.16s 24024KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 3, in <module>
    from opencc import OpenCC
ModuleNotFoundError: No module named 'opencc'