Пример #1
0
def test_multiple_queues(ordered=False, chunksize=1):
    info('\n* Testing execute(ordered=%s, chunksize=%d) - multiple queues *',
         ordered, chunksize)
    iter_tasks1 = (SlowSquare(i) for i in xrange(num_tasks))
    iter_results1 = dispatcher.execute(iter_tasks1, ordered=ordered, chunksize=chunksize)
    iter_tasks2 = (SlowSquare(float(i)) for i in xrange(num_tasks))
    iter_results2 = dispatcher.execute(iter_tasks2, ordered=ordered, chunksize=chunksize)
    num_results = 0
    for result1,result2 in izip(iter_results1,iter_results2):
        info('    Got (%r, %r)', result1, result2)
        num_results +=1
        assert isinstance(result1,int) and isinstance(result2,float)
    assert num_results == num_tasks
Пример #2
0
def test_pop_many(timeout=0):
    info('\n* Testing pop_many(timeout=%1.f) *', timeout)
    taskqueue = dispatcher.make_queue()
    try:
        for i in xrange(num_tasks):
            taskqueue.push(random_task(SlowSquare))
        try:
            results = taskqueue.pop_many(timeout)
            info('%d results: %s', len(results), results)
        except Exception, ex:
            exception_info(ex)
    finally:
        taskqueue.close()
Пример #3
0
def test_execute_exception(ordered, chunksize):
    info('\n* Testing execute(ordered=%s, chunksize=%d) - expecting exceptions *',
         ordered, chunksize)
    num_results = num_failures = 0
    iter_tasks = (random_task(PrimeFactors) for i in xrange(num_tasks))
    iter_results = dispatcher.execute(iter_tasks, ordered=ordered, chunksize=chunksize)
    for i in xrange(num_tasks):
        try:
            info('    Got %r', iter_results.next())
            num_results += 1
        except Exception, ex:
            num_failures += 1
            exception_info(ex)
Пример #4
0
def test_autoclose():
    info('\n* Testing automatic close() / garbage collection *')
    time.sleep(0.1) # give time for any previously closed queues to die off
    num_queues = dispatcher.num_queues()
    assert not num_queues, 'Starting with %d queues instead of 0' % num_queues
    # starting the queues in a separate function to make sure that no locals are
    # kept around after it returns
    def closure():
        for i in xrange(num_tasks):
            task = random_task(PrimeFactors)
            info('  Task: %s', task)
            try: dispatcher.execute([task]).next()
            except Exception, ex: pass
    closure()
    time.sleep(0.1) # give time for all closed queues to die off
    num_queues = dispatcher.num_queues()
    assert not num_queues, 'Ending with %d queues instead of 0' % num_queues
Пример #5
0
def test_close_execute():
    info('\n* Testing close() on execute() iterator *')
    iter_results = dispatcher.execute(SlowSquare(i) for i in xrange(num_tasks))
    for i in xrange(num_tasks//2):
        info('    Got %r', iter_results.next())
    iter_results.close()
    for i in xrange(num_tasks//2, num_tasks):
        try:
            info('    Got %r', iter_results.next())
        except papyros.ClosedTaskQueueError:
            info('    Task queue closed'); break
        except Exception, ex:
            # PyroTaskQueue may raise ProtocolError/ConnectionClosedError
            exception_info(ex); break
Пример #6
0
def test_execute(ordered, chunksize):
    info('\n* Testing execute(ordered=%s, chunksize=%d) - not expecting '
         'exceptions *', ordered, chunksize)
    num_results = 0
    iter_tasks = (SlowSquare(i) for i in xrange(num_tasks))
    for result in dispatcher.execute(iter_tasks, ordered=ordered, chunksize=chunksize):
        info('    Got %r', result)
        num_results += 1
    info('%d results', num_results)
    assert num_results == num_tasks
Пример #7
0
def test_close():
    info('\n* Testing close() *')
    taskqueue = dispatcher.make_queue()
    for i in xrange(num_tasks):
        taskqueue.push(random_task(SlowSquare))
    for i in xrange(num_tasks // 2):
        info('    Got %r', taskqueue.pop())
    taskqueue.close()
    for i in xrange(num_tasks // 2, num_tasks):
        try:
            info('    Got %r', taskqueue.pop())
        except papyros.ClosedTaskQueueError:
            info('    Task queue closed')
            break
        except Exception, ex:
            # PyroTaskQueue may raise ProtocolError/ConnectionClosedError
            exception_info(ex)
            break
Пример #8
0
def test_pop_nonblocking(timeout=0):
    info('\n* Testing non-blocking pop(timeout=%.1f) *', timeout)
    num_results = num_failures = 0
    taskqueue = dispatcher.make_queue()
    try:
        for i in xrange(num_tasks):
            taskqueue.push(random_task())
        while num_results + num_failures < num_tasks:
            try:
                info('    Got %r', taskqueue.pop(timeout))
                num_results += 1
            except papyros.TimeoutError:
                info(
                    '    Got nothing within the %.1f seconds timeout: '
                    'will check again later', timeout)
                time.sleep(0.1)
            except Exception, ex:
                num_failures += 1
                exception_info(ex)
    finally:
        taskqueue.close()
    info('%d results, %d failures', num_results, num_failures)
Пример #9
0
def test_pop_blocking():
    info('\n* Testing blocking pop() *')
    num_results = num_failures = 0
    taskqueue = dispatcher.make_queue()
    try:
        for i in xrange(num_tasks):
            taskqueue.push(random_task())
        for i in xrange(num_tasks):
            try:
                info('    Got %r', taskqueue.pop())
                num_results += 1
            except Exception, ex:
                num_failures += 1
                exception_info(ex)
    finally:
        taskqueue.close()
    info('%d results, %d failures', num_results, num_failures)
Пример #10
0
def request():
    user_request = str(input('\nLex:\\User\\command> '))
    return user_request.lower()


print(
    '\nLex Command Line (Version 0.1/Python/November 24, 2020) [Clarence Sarmiento]'
)
print('Type "-help", "-info" for more information.')
while True:
    command = request()
    if '-help' in command:
        help_command()
    elif '-info' in command:
        tasks.info()
    elif '-wifi' in command:
        wp.wifi_password()
    elif '-sched' in command:
        sched = command.split('-sched')[-1].strip()
        find.schedule(sched)
    elif '-search' in command:
        query = command.split('-search')[-1].strip()
        tasks.search(query)
    elif '-play' in command:
        title = command.split('-play')[-1].strip()
        tasks.youtube(title)
    elif '-file' in command:
        f_find.locate()
    elif '-facebook' in command or '-fb' in command:
        url = "https://www.facebook.com/"
Пример #11
0
 def closure():
     for i in xrange(num_tasks):
         task = random_task(PrimeFactors)
         info('  Task: %s', task)
         try: dispatcher.execute([task]).next()
         except Exception, ex: pass
Пример #12
0
    assert num_results == num_tasks

def test_execute_exception(ordered, chunksize):
    info('\n* Testing execute(ordered=%s, chunksize=%d) - expecting exceptions *',
         ordered, chunksize)
    num_results = num_failures = 0
    iter_tasks = (random_task(PrimeFactors) for i in xrange(num_tasks))
    iter_results = dispatcher.execute(iter_tasks, ordered=ordered, chunksize=chunksize)
    for i in xrange(num_tasks):
        try:
            info('    Got %r', iter_results.next())
            num_results += 1
        except Exception, ex:
            num_failures += 1
            exception_info(ex)
    info('%d results, %d failures', num_results, num_failures)
    assert num_results + num_failures == num_tasks

def test_multiple_queues(ordered=False, chunksize=1):
    info('\n* Testing execute(ordered=%s, chunksize=%d) - multiple queues *',
         ordered, chunksize)
    iter_tasks1 = (SlowSquare(i) for i in xrange(num_tasks))
    iter_results1 = dispatcher.execute(iter_tasks1, ordered=ordered, chunksize=chunksize)
    iter_tasks2 = (SlowSquare(float(i)) for i in xrange(num_tasks))
    iter_results2 = dispatcher.execute(iter_tasks2, ordered=ordered, chunksize=chunksize)
    num_results = 0
    for result1,result2 in izip(iter_results1,iter_results2):
        info('    Got (%r, %r)', result1, result2)
        num_results +=1
        assert isinstance(result1,int) and isinstance(result2,float)
    assert num_results == num_tasks