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
5
votes
0 answers

ExecutorService submit() doesn't work as expected with lambda version of Callable

I'm trying to write a mechanism that loads a few models concurrently (using ExecutorService) and retrieves their results when all are finished: List> modelFutures = new LinkedList>(); ExecutorService executor =…
KidCrippler
  • 1,633
  • 2
  • 19
  • 34
5
votes
3 answers

Print name or definition of callable in PHP

Callables in PHP can be in a lot of forms, like an object, an array, or a string containing a function name. If I got a callable like this in a variable how can I print some user friendly "definition" of it in the log. Think of this…
EdgarPE
  • 151
  • 1
  • 2
5
votes
1 answer

Is there a way to define the docstring for a python object that defines __call__?

I have a class that defines a __call__, but the when the user sees requests help for this "function" on the help return, they get the entire object and methods and it can be a bit daunting...I would like the help to look more like a function's help…
KevinP
  • 303
  • 1
  • 9
5
votes
1 answer

Java Callable : What happens to the thread before get() is called

More precisely : If I start async computation by calling submit(Callable task) method on an ExecutorService (itself constructed with Executors.newCachedThreadPool()), I can wait for the computation to finish and retrieve the result by calling…
5
votes
1 answer

matplotlib animation FuncAnimation frames argument

I'm using matplotlib animation by calling: plot = animation.FuncAnimation(fig, update, frames=data_gen(a), init_func=init, interval=10, blit=True) Here, "a" is an initial value for the data_gen function which looks like this: data_gen(x) old_x…
Riccati
  • 461
  • 4
  • 13
5
votes
4 answers

How to wait for all callables to finish executing before proceeding?

I have the following code hashed out: public class MyCallable implements Callable { @Override public Long call() throws Exception { // Do stuff... } } public class MyController { private ExecutorService executor =…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
4
votes
5 answers

Populate list or tuple from callable or lambda in python

This is a problem I've come across a lot lately. Google doesn't seem to have an answer so I bring it to the good people of stack overflow. I am looking for a simple way to populate a list with the output of a function. Something like…
Bryan Austin
  • 487
  • 3
  • 13
4
votes
1 answer

Why are my anonymous functions evaluating to NULL in Symfony 2.0?

I just started playing around with Symfony 2.0 and immediately ran into an error: [28-Nov-2011 16:51:26] PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A callable is expected in …
Jordan Brown
  • 13,603
  • 6
  • 30
  • 29
4
votes
2 answers

Event Driven Future - Thread Pool

We use callable and Future to receive the result of a terminated thread from a thread pool. We should call get() to receive the returned result. My problem is: it is not event driven. Is there any framework to get result like SIGCHLD for child…
Majid Azimi
  • 5,575
  • 13
  • 64
  • 113
4
votes
0 answers

How to indicate a callable is of a certain type?

For example, we can indicate a variable is of a certain type: a: float = 5. Can we also indicate that a function is of a certain type? import typing FunctionType = typing.Callable[[float],float] def a(v: float)->float: return v How do we…
Vince
  • 3,979
  • 10
  • 41
  • 69
4
votes
2 answers

why std::function that store a call to member function can have two different callable type

struct Foo { Foo(int num) : num_(num) {} void print_add(int i) const { std::cout << num_+i << '\n'; } int num_; }; int main () { function func = &Foo::print_add; function func2 =…
codesavesworld
  • 587
  • 3
  • 10
4
votes
1 answer

C++ 17: Deduce signature from Callable in a template

If and how is it possible to deduce the signature type from any callable in C++17? Snippet: template struct MyFunction; template struct MyFunction { }; template auto…
Juergen
  • 3,489
  • 6
  • 35
  • 59
4
votes
1 answer

Is it possible to make a class instance callable in Fortran?

I have a polynomial class TPoly, see the code below, which takes an array of coefficients coefs and evaluates the polynomial at some point x using the eval method. I was wondering whether it is possible to evaluate the polynomial directly by making…
Erwin
  • 43
  • 2
4
votes
4 answers

Parallel execution of callables

I'd like to execute multiple callables parallel. But it seems that the ExecutorService always waits until all callables are finnished. I've tried the following: final int nThreads = 10; ExecutorService executorService =…
Dänu
  • 5,791
  • 9
  • 43
  • 56
4
votes
2 answers

How to pass a Callable object in c++17 to be used with std::invoke

Why the following does not compile when passing i to the constructor. The other similar constructs compile. #include #include int RetXPrintU(int x, uint u) { std::cout << "RetXprintU(): " << u << std::endl; return…
pettitpeon
  • 87
  • 4