Пример #1
0
import uuid, time, os

from pylocker import Locker

FL = Locker(filePath='test.txt',
            mode='a',
            lockPass=str(uuid.uuid1()),
            lockPath='lock.txt')

n = 1000
ats = []
rts = []
for i in range(n):
    t0 = time.time()
    with FL as r:
        acquired, code, fd = r
        if not acquired:
            print(
                codes.get(
                    code,
                    "I was not able to set the lock, my code is '%s'." % code))
    t1 = time.time()
    ats.append(t1 - t0)

    # release lock
    t2 = time.time()
    FL.release_lock()
    rts.append(t2 - t1)

print("acquiring lock mean time for %i times: " % n,
      float(sum(ats)) / len(ats))
Пример #2
0
            #-----------------------------------------#
            #Micro-average AUC
            rmi=sklearn.metrics.roc_auc_score(y_test, y_prob.toarray(), average='micro', sample_weight=None, max_fpr=None)
            fold_auc.append(rmi)
            

        #-----------------------------------------#
        #Medidas: sklearn.metrics...(true,predict,..)
        acc= sklearn.metrics.accuracy_score(y_test, y_score)
        fold_accuracy.append(acc)
        #-----------------------------------------#
        hl=sklearn.metrics.hamming_loss(y_test, y_score)
        fold_hamming.append(hl)
    
    lpass = str(uuid.uuid1())
    FL = Locker(filePath=fname, lockPass=lpass, mode='a')
    
    with FL as r:
        acquired, code, fd = r

        if fd is not None:
            fd.write(str(s)+';')
            #fp.write("Accuracy: ")
            fd.write(str(sum(fold_accuracy)/len(fold_accuracy))+';')
            #fp.write("Hamming loss: ")
            fd.write(str(sum(fold_hamming)/len(fold_hamming))+';')

            #fp.write("Coverage: ")
            if len(fold_cover)>0:
                fd.write(str(sum(fold_cover)/len(fold_cover))+';')
Пример #3
0
"""
Launch many consoles and run the following scipt and verify how lock can be aquired
acquisition works.
"""
import uuid, time, os
from pylocker import Locker

n = 10000

FL = Locker(filePath='test.txt',
            lockPass=str(uuid.uuid1()),
            lockPath='lock.txt',
            wait=0,
            timeout=0.1)

codes = {
    0:
    'i am locked, no one can touch me. I will wait 2 seconds.',
    1:
    'lock was already set. I will wait 2 more seconds.',
    2:
    'Old and forgotten lock for more than %i seconds is removed. I am now locked, I will wait 2 seconds.'
    % FL.deadLock,
    3:
    'Exhau1ted my %s sec. timeout.' % FL.timeout
}

t0 = time.time()
for i in range(n):
    acquired, code = FL.acquire_lock()
    message = codes.get(
Пример #4
0
import uuid, time, os

from pylocker import Locker


FL = Locker(filePath='test.txt', mode='a', lockPass=str(uuid.uuid1()), lockPath='lock.txt')

n   = 1000
ats = []
rts = []
for i in range(n):
    t0 = time.time()
    with FL as r:
        acquired, code, fd = r
        if not acquired:
            print(codes.get(code, "I was not able to set the lock, my code is '%s'."%code) )
    t1 = time.time()
    ats.append( t1-t0 )

    # release lock
    t2 = time.time()
    released, code = FL.release_lock(raiseError=True)
    rts.append( t2-t1 )

print("acquiring lock mean time for %i times: "%n, float(sum(ats)) / len(ats) )
print("releasing lock mean time for %i times: "%n, float(sum(rts)) / len(rts) )