from multiprocessing import Process, Queue , freeze_support, Pool
import sys
import time
from fractions import gcd
from collections import Counter
PROCESSES = 10
q = Queue ( )
out = Queue ( )
t = 10 ** 5
t = 13
def get_passed_time( cur_time) :
cur_time = time .time ( ) - cur_time
if cur_time > 60 :
cur_time /= 60
label = 'mins'
else :
label = 'seconds'
return '%.5s %s' % ( cur_time, label)
def f( x) :
# print('hello')
# x = q.get()
if gcd( x, t) == 1 :
print ( x)
out.put ( x)
def create_set( t) :
init = time .time ( )
out = [ ]
for x in range ( 1 , t) :
if gcd( x, t) == 1 :
out.append ( x)
print ( 'set created in' , get_passed_time( init) )
return out
if __name__ == '__main__' :
COUNTER = Counter( )
for x in range ( t) :
q.put ( x)
init = time .time ( )
with Pool( processes= 2 ) as pool:
pool.map ( f, range ( t) )
print ( 'm_set created in' , get_passed_time( init) )
create_set( t)
print ( out.qsize ( ) )
ZnJvbSBtdWx0aXByb2Nlc3NpbmcgaW1wb3J0IFByb2Nlc3MsIFF1ZXVlLCBmcmVlemVfc3VwcG9ydCwgUG9vbAppbXBvcnQgc3lzCmltcG9ydCB0aW1lCmZyb20gZnJhY3Rpb25zIGltcG9ydCBnY2QKZnJvbSBjb2xsZWN0aW9ucyBpbXBvcnQgQ291bnRlcgoKClBST0NFU1NFUyA9IDEwCgpxID0gUXVldWUoKQpvdXQgPSBRdWV1ZSgpCgp0ID0gMTAgKiogNQp0ID0gMTMKCgpkZWYgZ2V0X3Bhc3NlZF90aW1lKGN1cl90aW1lKToKICAgIGN1cl90aW1lID0gdGltZS50aW1lKCkgLSBjdXJfdGltZQogICAgaWYgY3VyX3RpbWUgPiA2MDoKICAgICAgICBjdXJfdGltZSAvPSA2MAogICAgICAgIGxhYmVsID0gJ21pbnMnCiAgICBlbHNlOgogICAgICAgIGxhYmVsID0gJ3NlY29uZHMnCiAgICByZXR1cm4gJyUuNXMgJXMnICUgKGN1cl90aW1lLCBsYWJlbCkKCgpkZWYgZih4KToKICAgICMgcHJpbnQoJ2hlbGxvJykKICAgICMgeCA9IHEuZ2V0KCkKICAgIGlmIGdjZCh4LCB0KSA9PSAxOgogICAgICAgIHByaW50KHgpCiAgICAgICAgb3V0LnB1dCh4KQoKCmRlZiBjcmVhdGVfc2V0KHQpOgogICAgaW5pdCA9IHRpbWUudGltZSgpCiAgICBvdXQgPSBbXQogICAgZm9yIHggaW4gcmFuZ2UoMSwgdCk6CiAgICAgICAgaWYgZ2NkKHgsIHQpID09IDE6CiAgICAgICAgICAgIG91dC5hcHBlbmQoeCkKICAgIHByaW50KCdzZXQgY3JlYXRlZCBpbicsIGdldF9wYXNzZWRfdGltZShpbml0KSkKICAgIHJldHVybiBvdXQKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBDT1VOVEVSID0gQ291bnRlcigpCgogICAgZm9yIHggaW4gcmFuZ2UodCk6CiAgICAgICAgcS5wdXQoeCkKCiAgICBpbml0ID0gdGltZS50aW1lKCkKCiAgICB3aXRoIFBvb2wocHJvY2Vzc2VzPTIpIGFzIHBvb2w6CiAgICAgICAgcG9vbC5tYXAoZiwgcmFuZ2UodCkpCgogICAgcHJpbnQoJ21fc2V0IGNyZWF0ZWQgaW4nLCBnZXRfcGFzc2VkX3RpbWUoaW5pdCkpCiAgICBjcmVhdGVfc2V0KHQpCiAgICBwcmludChvdXQucXNpemUoKSkK
stdout
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