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
10
votes
3 answers

Why does the 'int' object is not callable error occur when using the sum() function?

I'm trying to figure out why I'm getting an error when using the sum function on a range. Here is the code: data1 = range(0, 1000, 3) data2 = range(0, 1000, 5) data3 = list(set(data1 + data2)) # makes new list without duplicates total = sum(data3) #…
mattste
  • 360
  • 1
  • 3
  • 14
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
  • 10,623
  • 20
  • 93
  • 149
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
  • 21,220
  • 37
  • 123
  • 171
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,221
  • 1
  • 13
  • 30
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,780
  • 5
  • 44
  • 74
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…
user3787186
  • 91
  • 1
  • 1
  • 3
9
votes
5 answers

What happens to a BufferedReader that doesn't get closed within a callable.call?

I have three questions. To explain, I was reviewing someone's code, and noticed BufferedReaders sometimes aren't being closed. Usually, Eclipse gives a warning that this is a potential memory leak (and I fix it). However, within a Callable inner…
GLaDOS
  • 683
  • 1
  • 14
  • 29
8
votes
3 answers

How to return object from Callable()

I'm trying to return a 2d array from call(), I'm having some issues. My code so far is: //this is the end of main Thread t1 = new Thread(new ArrayMultiplication(Array1, Array2, length)); t1.start(); } public int[][] call(int[][] answer) …
user650309
  • 2,639
  • 7
  • 28
  • 47
8
votes
5 answers

Where to use callable and where to use Runnable Interface?

I am quite new to Java, I was going through concepts of Multithreading, while going through various implementation of using multithreading, I went through these two concepts. This The difference between the Runnable and Callable interfaces in Java…
Geek_To_Learn
  • 1,816
  • 5
  • 28
  • 48
8
votes
2 answers

Callable Objects with different calling conventions

At the moment I'm building functors (callable types) for the different calling conventions (__stdcall, __cdecl, __fastcall etc.). With the wrappers I'll be able to do something like this: void __stdcall foo(int arg) { std::printf("arg: %i\n",…
Michael Kiros
  • 563
  • 4
  • 11
8
votes
1 answer

Java 8 Function vs Consumer

I can't for the life of me find an explanation of the following: public static void takesAFunction(Function func) { func.apply("Hi I'm running a function"); } public static void takesAConsumer(Consumer func) { …
RVP
  • 2,330
  • 4
  • 23
  • 34
8
votes
1 answer

Why are Python decorators with arguments syntactically different from those without?

This article, linked to a number of times from various stackoverflow questions, describes how decorators with arguments are syntactically different from those without arguments. Decorators without arguments: "Notice that __init__() is the only…
kuzzooroo
  • 6,788
  • 11
  • 46
  • 84
8
votes
2 answers

Proper way to handle Thread.interrupted() in a Callable?

What is the proper way to handle Thread.interrupted() in a Callable? I'm guessing that the callable should throw an InterruptedException; for example: public class MyCallable implements Callable { public Object call() { Object…
Greg Brown
  • 3,168
  • 1
  • 27
  • 37
8
votes
4 answers

Do you use nouns for classnames that represent callable objects?

There is a more generic question asked here. Consider this as an extension to that. I understand that classes represent type of objects and we should use nouns as their names. But there are function objects supported in many language that acts more…
Vikas
  • 8,790
  • 4
  • 38
  • 48
7
votes
2 answers

How to register typing.Callable with Python @singledispatch?

Background Suppose I am to implement a simple decorator @notifyme that prints a message when the decorated function is invoked. I would like the decorator to accept one argument to print a customized message; the argument (along with the parentheses…
Yang Hanlin
  • 474
  • 1
  • 6
  • 18