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

Dynamically assigning function implementation in Python

I want to assign a function implementation dynamically. Let's start with the following: class Doer(object): def __init__(self): self.name = "Bob" def doSomething(self): print "%s got it done" % self.name def…
Yarin
  • 144,097
  • 139
  • 361
  • 489
18
votes
2 answers

making a class callable in same instance

class Foo(object): def tick(self): print("something") class Bar(object): def __init__(self): self.foo = Foo() def tick(self): #Here's what I do.... self.foo.tick() #here's what my goal would be …
DanielCardin
  • 385
  • 2
  • 8
  • 14
17
votes
6 answers

What does the keyword "callable" do in PHP

To be more exact, the "callable" used in function declaration arguments. like the one below. function post($pattern, callable $handler) { $this->routes['post'][$pattern] = $handler; return $this; } How does it benefit us? why and how do we…
17
votes
2 answers

What is the difference between std::invoke and std::apply?

They are both used as a generic method of calling functions, member functions and generally anything that is callable. From cppreference the only real difference I see is that in std::invoke the function parameters (however many they are) are…
KeyC0de
  • 3,375
  • 5
  • 35
  • 50
17
votes
2 answers

executing a method in parallel from a call method

I have a library which is being used by customer and they are passing DataRequest object which has userid, timeout and some other fields in it. Now I use this DataRequest object to make a URL and then I make an HTTP call using RestTemplate and my…
john
  • 9,493
  • 34
  • 111
  • 210
17
votes
5 answers

Understanding Java FixedThreadPool

I am trying to understand how Java FixedThreadPool works in practice, but the docs do not answer my question. Assume a simple scenario like: ExecutorService ES= Executors.newFixedThreadPool(3); List FL; for(int i=1;i<=200;i++){ …
k88074
  • 1,742
  • 2
  • 24
  • 39
16
votes
2 answers

How to code/reference to a PHP callable functions easy to manage for my IDE

When I have to write a reference to a callable function I use the standard syntax of PHP defined as: A PHP function is passed by its name as a string. Any built-in or user-defined function can be used [... omitted...]. A method of an instantiated…
Ivan Buttinoni
  • 3,775
  • 1
  • 19
  • 33
16
votes
2 answers

How to declare Callable to execute function returning void in Java?

Suppose I would like to run static method foo asynchronously void foo() throws Exception {...} Since foo throws an exception I would prefer create a Callable and invoke ExecutorService.submit with it to get a Future. Now I wonder how to declare…
Michael
  • 37,415
  • 63
  • 167
  • 303
15
votes
7 answers

How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?

I have a method that I would like to call. However, I'm looking for a clean, simple way to kill it or force it to return if it is taking too long to execute. I'm using Java. to illustrate: logger.info("sequentially executing all batches..."); for…
carrier
  • 29,579
  • 22
  • 74
  • 99
14
votes
4 answers

timeit ValueError: stmt is neither a string nor callable

I played with timeit in Python, got a weird problem. I define a simple function add. timeit works when I pass add two string parameters. But it raises ValueError: stmt is neither a string nor callable when I pass add two int parameters. >>>…
liang li
  • 193
  • 1
  • 1
  • 7
14
votes
2 answers

Is a generator the callable? Which is the generator?

A generator is simply a function which returns an object on which you can call next, such that for every call it returns some value, until it raises a StopIteration exception, signaling that all values have been generated. Such an object is called…
du369
  • 755
  • 5
  • 19
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
  • 463
  • 2
  • 5
  • 6
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
  • 5
12
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,147
  • 2
  • 21
  • 28
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
  • 9,885
  • 2
  • 50
  • 68
1
2
3
43 44