fork download
  1. from multiprocessing import Process, Queue, freeze_support, Pool
  2. import sys
  3. import time
  4. from fractions import gcd
  5. from collections import Counter
  6.  
  7.  
  8. PROCESSES = 10
  9.  
  10. q = Queue()
  11. out = Queue()
  12.  
  13. t = 10 ** 5
  14. t = 13
  15.  
  16.  
  17. def get_passed_time(cur_time):
  18. cur_time = time.time() - cur_time
  19. if cur_time > 60:
  20. cur_time /= 60
  21. label = 'mins'
  22. else:
  23. label = 'seconds'
  24. return '%.5s %s' % (cur_time, label)
  25.  
  26.  
  27. def f(x):
  28. # print('hello')
  29. # x = q.get()
  30. if gcd(x, t) == 1:
  31. print(x)
  32. out.put(x)
  33.  
  34.  
  35. def create_set(t):
  36. init = time.time()
  37. out = []
  38. for x in range(1, t):
  39. if gcd(x, t) == 1:
  40. out.append(x)
  41. print('set created in', get_passed_time(init))
  42. return out
  43.  
  44. if __name__ == '__main__':
  45. COUNTER = Counter()
  46.  
  47. for x in range(t):
  48. q.put(x)
  49.  
  50. init = time.time()
  51.  
  52. with Pool(processes=2) as pool:
  53. pool.map(f, range(t))
  54.  
  55. print('m_set created in', get_passed_time(init))
  56. create_set(t)
  57. print(out.qsize())
  58.  
Runtime error #stdin #stdout #stderr 0.1s 13512KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 10, in <module>
  File "/usr/lib/python3.4/multiprocessing/context.py", line 101, in Queue
    return Queue(maxsize, ctx=self.get_context())
  File "/usr/lib/python3.4/multiprocessing/queues.py", line 41, in __init__
    self._rlock = ctx.Lock()
  File "/usr/lib/python3.4/multiprocessing/context.py", line 66, in Lock
    return Lock(ctx=self.get_context())
  File "/usr/lib/python3.4/multiprocessing/synchronize.py", line 163, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
  File "/usr/lib/python3.4/multiprocessing/synchronize.py", line 60, in __init__
    unlink_now)
OSError: [Errno 38] Function not implemented