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.

655 questions
11
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
  • 41,098
  • 25
  • 141
  • 183
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
  • 598
  • 3
  • 6
  • 16
11
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
  • 20,450
  • 13
  • 52
  • 77
10
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
  • 127
  • 1
  • 1
  • 8
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
  • 9,493
  • 34
  • 111
  • 210
10
votes
1 answer

Python 3: Making a str object callable

I have a Python program that takes user input. I store user input a string variable called "userInput". I want to be able to call the string the user entered... userInput = input("Enter a command: ") userInput() From this, I get the error:…
just_a_programmer
  • 181
  • 1
  • 2
  • 9
10
votes
1 answer

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.
  • 6,664
  • 10
  • 55
  • 74
10
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
  • 639
  • 2
  • 7
  • 19
9
votes
4 answers

java Callable FutureTask Excecuter: How to listen to finished task

I'm quite new to executer services. Liked doing everything myself, but I think it's time to trust these services. I want to hand by Executer a Runnable. The executer wraps that in a FutureTask and hands it back to me. Now I call poll the done()…
Franz Kafka
  • 9,999
  • 17
  • 86
  • 145
9
votes
4 answers

How to ensure garbage collection of a FutureTask that is submitted to a ThreadPoolExecutor and then cancelled?

I am submitting Callable objects to a ThreadPoolExecutor and they seem to be sticking around in memory. Looking at the heap dump with the MAT tool for Eclipse see that the Callable objects are being referenced by a FutureTask$Sync's callable…
cottonBallPaws
  • 20,217
  • 37
  • 119
  • 169
9
votes
3 answers

Generating a sequence of type T at compile time

I have the following problem: template< typename callable, typename T , size_t... N_i> void foo() { using callable_out_type = std::result_of_t< callable( /* T , ... , T <- sizeof...(N_i) many */ ) >; // ... } I want to get the result type of…
abraham_hilbert
  • 2,091
  • 8
  • 26
9
votes
3 answers

PHP - Callable method not as array

Usually in PHP if you have a method bar of a class Foo and you'd like to pass it around as a callable, you use something like $foo = new Foo(); $callable = [$foo, 'bar']; The downside of this is that is_array($callable) evaluates to true. Is there…
marcosh
  • 8,079
  • 2
  • 41
  • 64
9
votes
4 answers

Java - Define a timeout for Callable within a ExecutorCompletionService

I've got the following problem using ExecutorCompletionService. I want to call a lot of Callable in different Threads. These Callable don't share any information with each other. I need to define a timeout for each Callable, eg. do not run longer…
9
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
  • 93
  • 1
  • 3
1 2
3
43 44