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

returning a user defined function name when using a decorator with a callable object

Consider the following code fragment. def print_timing(func): import time def wrapper(*args, **kwargs): t1 = time.time() res = func(*args, **kwargs) t2 = time.time() print '%s took %0.3f s ~ %0.0f min and…
Faheem Mitha
  • 6,096
  • 7
  • 48
  • 83
2
votes
1 answer

"List object not callable"

I'm currently writing a Python based tool for Maya. I'm using a line of code which I have used in countless other sections of other tools, and for some reason it refuses to work this time round. I cannot see any reason why it isn't. def…
Tom Rowell
  • 21
  • 1
  • 2
2
votes
1 answer

Spring Env is null when a class is implementing Callable interface

I am trying to Autowire Environment class into my class Customer for example. public class Customer implements Callable { @Autowired private Environment env; //dao logic } Also I have my main method…
Brooklyn99
  • 987
  • 13
  • 24
2
votes
3 answers

What is the best type for a callable object in a template method?

Every time I write a signature that accepts a templated callable, I always wonder what the best type for the parameter is. Should it be a value type or a const reference type? For example, template void execute_func(Func func) { /*…
scx
  • 3,221
  • 1
  • 19
  • 37
2
votes
0 answers

How do you print out the value you get from call() function in callable?

public double[] call() throws Exception { int [] zero = {0,0}; double [] return_to_thread = { }; List
xxColderxx
  • 53
  • 6
2
votes
2 answers

Callable instead of Runnable so I do not need a catch

I defined a Future in the following way: Future future = null; ExecutorService service = null; First I used (just playing to get to know the stuff): future = service.submit(() -> { for (int…
Cecil
  • 41
  • 7
2
votes
0 answers

How to make user-defined callable weight function for sklearn knn?

I am trying to make custom weights for Sklearn KNN classifier, similar as here. In documentation is just briefly mentioned that you can set custom weights as a user-defined function which accepts an array of distances, and returns an array of the…
Rosa
  • 155
  • 10
2
votes
2 answers

Extra bytes appearing when building file data using multiple threads

I am working on a large scale dataset and after building a model, I use multithreading (whole project in Java) as follows: OutputStream out = new BufferedOutputStream(new FileOutputStream(outFile)); int i=0; Collection callables =…
dreamer13134
  • 471
  • 1
  • 6
  • 19
2
votes
1 answer

Using Callable instead of Supplier or vice versa

I came across code that used Callable instead of Supplier. I did not see any threads spawning across to use Callable. But is it okay to use Callable instead of Supplier?. One of the devs I work with stated that it does the same job. Going by the…
serah
  • 2,057
  • 7
  • 36
  • 56
2
votes
2 answers

Why is a reference to a type that implements Fn not recognized as a callable?

Even if &T is defined as implementing the Fn trait, the compiler rejects it when invoking it is as a callable: trait Trait { fn act(self); } //passes fn test_ref_input_as_trait<'a, T>(t: &'a T) where &'a T: Trait, { …
vikram2784
  • 783
  • 7
  • 14
2
votes
2 answers

Firebase Promises Issue - "Maximum call stack size exceeded"

I'm having an issue with Callable Functions. Here's my Firebase function: const functions = require('firebase-functions'); const admin = require('firebase-admin'); const request =…
2
votes
0 answers

Convert SecretBytes to String and viceversa

I am trying to get zip file content into a secretbytes and converting it to bytes and writing it to a file.zip, Zip is properly working. When i convert secretbytes to string then to secretbytes and then to bytes and writing it to a file.zip, now…
Sai Lakshmi
  • 59
  • 1
  • 7
2
votes
2 answers

Can we get the Callable object from a Future object in Java?

I have a list of callable objects , which I am using to generate a list of future objects. I am using ExecutorService to get the Callable tasks done concurrently and storing the result as list of Future objects. Now I want to know, is there a way so…
2
votes
2 answers

Async return with delay - IllegalMonitorStateException

I am trying to call method in new thread which will return something after delay using callable. It is falling due to IllegalMonitorStateException Is it possible to encapsulate thread service that way, when I will just create instance of class, call…
2
votes
2 answers

How do I unit-test a Callable lambda expression?

I have a piece of Java code that I need to unit-test with PowerMockito: public class MyClass { public Response someMethod() { Response response = Wrapper.wrap( () -> { return OtherClass.doSomething(); }); // .... do something…
Yuval
  • 7,987
  • 12
  • 40
  • 54