Exemplo n.º 1
0
 def parent(self):
     print('- wait for child with timeout:')
     tstart = time()
     s = sem_take(sid, 0, wait=2 * delay)
     if time() - tstart < delay:
         self.errmsg = 'timeout too quickly.'
         return -2
     return s
Exemplo n.º 2
0
 def parent(self):
   print('- wait for child with timeout:')
   tstart=time()
   s = sem_take(sid, 0, wait= 2 * delay)
   if time()-tstart < delay:
     self.errmsg='timeout too quickly.'
     return -2
   return s
Exemplo n.º 3
0
 def parent(self):
     print('- wait for child with timeout, and timeout:')
     tstart = time()
     s = sem_take(sid, 0, wait=delay)
     if time() - tstart < delay:
         self.errmsg = 'did not wait long enough'
         return -2
     self.errmsg = 'wait did not time out.'
     return not s
Exemplo n.º 4
0
 def parent(self):
   print('- wait for child with timeout, and timeout:')
   tstart=time()
   s = sem_take(sid, 0, wait=delay)
   if time()-tstart < delay:
     self.errmsg='did not wait long enough'
     return -2
   self.errmsg='wait did not time out.'
   return not s
Exemplo n.º 5
0
 def parent(self):
     print('- try take semaphore (available):')
     sleep(delay)
     s = sem_take(sid, 0, wait=0)
     self.errmsg = 'sem was not available'
     return s
Exemplo n.º 6
0
 def parent(self):
     print('- wait for child x10 times:')
     s = sem_take(sid, 0, count=10)
     return s
Exemplo n.º 7
0
 def parent(self):
     print('- wait for child forever:')
     s = sem_take(sid, 0)
     return s
Exemplo n.º 8
0
 def parent(self):
   print('- try take semaphore (non-available):')
   s = sem_take(sid, 0, wait=0)
   self.errmsg='sem was available'
   return not s 
Exemplo n.º 9
0
n = 32

stoopid=numpy.ones(n)
stoopid[n-1]=n
data = numpy.arange(n).reshape(stoopid)
#print data.shape


# create id
svid0 = 0x7dcb0000 | getpid()
svid1 = svid0+1

# create a pool with one shmaphore
shm_init(svid0,slots=1)
sem_init(svid1,nums=1)

if fork():
  for i in range(num_):
    shm_write(svid0,'slot0',data,publish=0) # shm id's are string ... doh
    sem_take(svid1,0)
else:
  time.sleep(1)
  for i in range(num_):
    d=shm_read(svid0,'slot0',0)
    sem_give(svid1,0)
    ### print d
  exit()

sem_cleanup(svid1)
shm_cleanup(svid0)
Exemplo n.º 10
0
 def parent(self):
   print('- wait for child x10 times:')
   s = sem_take(sid, 0, count=10)
   return s
Exemplo n.º 11
0
 def parent(self):
   print('- wait for child forever:')
   s = sem_take(sid, 0)
   return s
Exemplo n.º 12
0
# tell it to go
sys.stderr.write('P: yorick may go.\n')
svipc.sem_give(my_semid,id=0)

# play 1
for i in range(3):
   time.sleep(1)
   sys.stderr.write('P: sem give %d.\n' % i)
   svipc.sem_give(key=my_semid,id=0)


# play 2

sys.stderr.write('P: wait synch from yorick\n')

svipc.sem_take(my_semid,1)

sys.stderr.write('P: going now\n')

for i in range(3):
   msg = svipc.shm_read(my_shmid,id="pingpong",subscribe=-1.0)
   time.sleep(1)
   msg[i]=0
   svipc.shm_write(my_shmid,"pingpong",data=msg,publish=1)
  
# play 3

sys.stderr.write('P: wait synch from yorick\n')
svipc.sem_take(my_semid,1)
sys.stderr.write('P: going now\n')
Exemplo n.º 13
0
# tell it to go
sys.stderr.write('P: yorick may go.\n')
svipc.sem_give(my_semid, id=0)

# play 1
for i in range(3):
    time.sleep(1)
    sys.stderr.write('P: sem give %d.\n' % i)
    svipc.sem_give(key=my_semid, id=0)

# play 2

sys.stderr.write('P: wait synch from yorick\n')

svipc.sem_take(my_semid, 1)

sys.stderr.write('P: going now\n')

for i in range(3):
    msg = svipc.shm_read(my_shmid, id="pingpong", subscribe=-1.0)
    time.sleep(1)
    msg[i] = 0
    svipc.shm_write(my_shmid, "pingpong", data=msg, publish=1)

# play 3

sys.stderr.write('P: wait synch from yorick\n')
svipc.sem_take(my_semid, 1)
sys.stderr.write('P: going now\n')
Exemplo n.º 14
0
 def parent(self):
     print('- try take semaphore (non-available):')
     s = sem_take(sid, 0, wait=0)
     self.errmsg = 'sem was available'
     return not s
Exemplo n.º 15
0
 def parent(self):
   print('- try take semaphore (available):')
   sleep(delay)
   s = sem_take(sid, 0, wait=0)
   self.errmsg='sem was not available'
   return s 
Exemplo n.º 16
0
#let yorick wait ..
time.sleep(1)

# tell it to go
svipc.sem_give(my_semid,id=0)

# play 1

for i in range(3):
   time.sleep(1)
   svipc.sem_give(key=my_semid,id=0)

# play 2

svipc.sem_take(my_semid,0)

for i in range(3):
   msg = svipc.shm_read(my_shmid,id="pingpong",subscribe=-1.0)
   time.sleep(1)
   msg[i]=0
   svipc.shm_write(my_shmid,"pingpong",data=msg,publish=1)
  
# play 3

for i in range(3):
   msg = svipc.msq_rcv(my_msqid,mtype=1234)
   msg[i]=0
   svipc.msq_snd(my_msqid,mtype=5678,data=msg)

Exemplo n.º 17
0
n = 32

stoopid = numpy.ones(n)
stoopid[n - 1] = n
data = numpy.arange(n).reshape(stoopid)
#print data.shape

# create id
svid0 = 0x7dcb0000 | getpid()
svid1 = svid0 + 1

# create a pool with one shmaphore
shm_init(svid0, slots=1)
sem_init(svid1, nums=1)

if fork():
    for i in range(num_):
        shm_write(svid0, 'slot0', data,
                  publish=0)  # shm id's are string ... doh
        sem_take(svid1, 0)
else:
    time.sleep(1)
    for i in range(num_):
        d = shm_read(svid0, 'slot0', 0)
        sem_give(svid1, 0)
        ### print d
    exit()

sem_cleanup(svid1)
shm_cleanup(svid0)