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

What does it mean for a class to be callable?

I am trying to understand what 'callables' are in Python and what it means for a class to be callable. I was playing with the following code: class A(object): def __init__(self): pass print("Is A callable? " + str(callable(A))) a =…
Kevin L.
  • 1,371
  • 11
  • 24
7
votes
4 answers

invokeAll() is not willing to accept a Collection>

I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads); class DocFeeder implements Callable {....} ... List list = new LinkedList(); list.add(new…
Yossale
  • 14,165
  • 22
  • 82
  • 109
7
votes
5 answers

How can we convert a callable into a runnable

I have a class which implements the callable interface. I want to schedule a task for the class using scheduleAtFixedRate method of ScheduledExecutorService interface. However scheduleAtFixedRate needs a runnable object as a command which it can…
7
votes
2 answers

"TypeError: native Qt signal is not callable" with custom slots

The Environment I am running an Anaconda environment with Python 3.4. I am using PyCharm as my IDE. The Objective I am trying to make a pyQt4 QPushButton connect to a custom function: button.clicked().connect([method reference or…
Xorgon
  • 498
  • 1
  • 5
  • 20
7
votes
2 answers

Java : How to return intermediate results from a Thread

Using Java 7 I am trying to build a watcher that watches a data store (some collection type) and then will return certain items from it at certain points. In this case they are time stamps, when a timestamp passes the current time I want it to be…
perkss
  • 1,037
  • 1
  • 11
  • 37
7
votes
5 answers

How to produce a "Callable function"

I am currently writing a python definition called f_from_data which uses interpolation find point on a line so far I have written this: def f_from_data(xs, ys, x): xfine = np.linspace(min(xs), max(xs), 10000) y0 = inter.interp1d(xs, ys, kind…
GBA13
  • 205
  • 1
  • 2
  • 9
7
votes
1 answer

'int' object is not callable error in python

I'm getting this error: Traceback (most recent call last): File "C:\Users\George\Desktop\ex3.py", line 15, in s=s+d*2(-1/6.)*(u-1)*(u-2)*(u+2)*(u-4) TypeError: 'int' object is not callable Here is my…
GeorgeDavidKing
  • 149
  • 2
  • 3
  • 10
7
votes
2 answers

Callable with different return types

I would like to execute different methods in a separate thread depending on the parameters that are given to the constructor. However, the Callable interface only allows one kind of return parameter. It should work like this: Future result…
user1812379
  • 827
  • 3
  • 11
  • 22
7
votes
3 answers

Using callable(x) vs. hasattr(x, "__call__")

I'm writing Python that targets versions 3.2 and higher. It looks like using the built-in function callable is the most straightforward and efficient way to do this. I've seen recommendations for hasattr(x, "__call__"), collections.Callable(x), and…
bmacnaughton
  • 4,950
  • 3
  • 27
  • 36
7
votes
2 answers

dynamically adding callable to class as instance "method"

I implemented a metaclass that tears down the class attributes for classes created with it and builds methods from the data from those arguments, then attaches those dynamically created methods directly to the class object (the class in question…
Silas Ray
  • 25,682
  • 5
  • 48
  • 63
7
votes
3 answers

How to pass arguments to callable method specifically for register_shutdown_function?

I have method, in this method may be happened fatal error, for catching this error I make this class a { function shutDownFunction() { $error = error_get_last(); if ($error['type'] == 1) { echo "this is fatal…
Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236
6
votes
1 answer

Decorator class and missing required positional arguments

I'm having problems with a wrapper class, and can't figure out what I'm doing wrong. How do I go about getting that wrapper working with any class function with the 'self' argument? This is for Python 3.7.3. The thing is I remember the wrapper…
6
votes
2 answers

Callable lambda expression with argument

I am trying to implement "TaskExecutor" with generics (my first attempt to use generics) and using ExecutorService. Here is my "TaskExecutor" class: public class ExecuteAlerterTask { public List process(String executorName, Callable
lapkritinis
  • 2,664
  • 4
  • 19
  • 29
6
votes
1 answer

How do you make a callable object in Clojure?

How do you make a callable type or object in Clojure? For example, how could I define a record Foo taking a single value :bar which could be called to print that value? user=> (def foo (Foo. "Hello world")) user=> (foo) Hello World user=> (:bar…
Jeremy
  • 1
  • 85
  • 340
  • 366
6
votes
1 answer

how to use callback functions with object/method pair

I have a simple method which accepts a function to call this back later: def SimpleFunc(parm1): print(parm1) class CallMe: def __init__(self, func): self.func = func def Call(self, parm): self.func(parm) caller =…
Klaus
  • 24,205
  • 7
  • 58
  • 113