Questions tagged [callable]

A task that returns a result and may throw an exception.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

759 questions
14
votes
2 answers

How do I fix this "TypeError: 'str' object is not callable" error?

I'm creating a basic program that will use a GUI to get a price of an item, then take 10% off of the price if the initial price is less than 10, or take 20% off of the price if the initial price is greater than ten: import…
user2443381
  • 513
  • 2
  • 5
  • 6
14
votes
5 answers

Unit test succeeds in debug mode but fails when running it normally

Why does my unit test succeed in debug mode but fail when running it normally? public class ExecutorServiceTest extends MockitoTestCase{ private int numThreads; private ExecutorService pool; private volatile boolean interruptedBitSet; …
Chris Morris
  • 4,335
  • 4
  • 24
  • 28
12
votes
2 answers

Python static method is not always callable

While parsing attributes using __dict__, my @staticmethod is not callable. Python 2.7.5 (default, Aug 29 2016, 10:12:21) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from…
oHo
  • 51,447
  • 27
  • 165
  • 200
12
votes
3 answers

alternative to callable(),for use in Python 3

I looked at this thread but some of the concepts are above my current level. In Python 2.x, the callable() built-in method exists; is there a simple way to check to see if something is callable or not using Python 3?
Sophia
  • 155
  • 1
  • 6
12
votes
3 answers

Why do we have callable objects in python?

What is the purpose of a callable object? What problems do they solve?
StackUnderflow
  • 24,080
  • 14
  • 54
  • 77
12
votes
4 answers

Constructor for callable object in JavaScript

How can I make constructor for callable object in JavaScript? I've attempted various ways, like following. The example there is just shortened example of actual object. function CallablePoint(x, y) { function point() { // Complex…
Konrad Borowski
  • 11,584
  • 3
  • 57
  • 71
11
votes
3 answers

Getting a result in the future?

I'm looking to get a result from a method which can take a while to complete and doesn't actually return the object, so I'd like to deal with it as effectively as possible. Here's an example of what I'm trying to achieve: public static void main…
Anonomoose
  • 137
  • 1
  • 1
  • 8
11
votes
3 answers

In c++ 11, how to invoke an arbitrary callable object?

The concept of callable is defined in http://en.cppreference.com/w/cpp/concept/Callable. Suppose I have a callable object f that has one argument of type T* and return type void. f can be any callable type (a function object, a pointer to member…
user3547691
  • 227
  • 2
  • 9
11
votes
1 answer

Callable as Functional Interface with lambdas

I am just learning about new java8 features. And here is my question: Why is it not allowed to use Callable as a functional interface for lambda expressions? (Compiler complains about returning value) And it is still perfectly legal to use…
ferrerverck
  • 618
  • 3
  • 9
  • 17
11
votes
2 answers

How to get foreign key values with getattr from models

I have a model Project and i am getting the attributes of that with the following instr attr = getattr(project, 'id', None) project is the instance, id is the field and None is the default return type. My question is: what if I want to get the…
A.J.
  • 8,557
  • 11
  • 61
  • 89
11
votes
3 answers

Actual implementation of Callable and Future

I am in the process of understanding fine grain util.concurrency. Where is implementation of the Java Callable and Future located in the JVM ? I have found the Future class where it describes the future on the high level in Java lang, I am trying…
Peter
  • 689
  • 2
  • 8
  • 20
10
votes
1 answer

mypy error: Callable has no attribute "__get__"

I have something like the following: from typing import TypeVar, Callable, Generic, Type, Union, Optional T = TypeVar("T") V = TypeVar("V") class DescClass(Generic[T, V]): """A descriptor.""" def __init__(self, func: Callable[[T], V]) ->…
Rick
  • 43,029
  • 15
  • 76
  • 119
10
votes
1 answer

How to return a value using CompletableFuture

I created an example, i want to know how can I return a value using the CompletableFuture ? I also changed the CompletableFuture exeFutureList to be CompletableFuture exeFutureList but eclipse always suggest to set it back to…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
10
votes
2 answers

How to better use ExecutorService in multithreading environment?

I need to make a library in which I will have synchronous and asynchronous methods in it. executeSynchronous() - waits until I have a result, returns the result. executeAsynchronous() - returns a Future immediately which can be processed after…
john
  • 11,311
  • 40
  • 131
  • 251
10
votes
4 answers

Python property callable

Is there any way to have a property and a method with the same name? I mean a property that can be used the usual way and to be callable at the same time? Like this: >>> b = Book() >>> b.pages 123 >>> b.pages() 123 >>>…
Zahory
  • 103
  • 1
  • 4
1 2
3
50 51