def test_reject_recursive_repeats_multithreaded():
    @reject_recursive_repeats
    def recurse(sleep_now):
        time.sleep(sleep_now)
        try:
            recurse(0.05)
            return True
        except ValueError:
            return False

    thd1 = spawn(recurse, 0)
    thd2 = spawn(recurse, 0.02)
    assert thd2.get() and thd1.get()
Exemplo n.º 2
0
 def request_async(self, raw_method, raw_params):
     request_id = uuid.uuid4()
     self.pending_requests[request_id] = spawn(
         self.request_blocking,
         raw_method=raw_method,
         raw_params=raw_params,
     )
     return request_id
Exemplo n.º 3
0
def test_spawning_simple_thread():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True

    thread = spawn(target_fn)
    thread.join()

    assert container['success'] is True
Exemplo n.º 4
0
def test_spawning_specific_thread_class():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True

    thread = spawn(target_fn, thread_class=CustomThreadClass)
    thread.join()

    assert isinstance(thread, CustomThreadClass)

    assert container['success'] is True
Exemplo n.º 5
0
def test_thread_with_return_value():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True
        return 12345

    thread = spawn(target_fn)
    thread.join()

    assert container['success'] is True

    assert thread.get() == 12345