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
1 answer

why fct.__call__() is not the same as fct()?

the __call__ dunder method of a class is supposed to represent the operator (), correct? if so, why the following code is not working as expected? def f(): print("hello world") f() >>>hello world f.__call__ = lambda: print("foo") #replace the…
DB3D
  • 186
  • 1
  • 12
2
votes
2 answers

How to return a value from a function which was passed another function (with arguments) as an argument? I get a TypeError

Edit: Sorry for not elaborating on this earlier. My function that I pass actually has arguments. It looks kind of like this: ... time_elapsed = get_running_time(runner(x:int, y:int, z:int, return_values:list)) ... I pass a list as return_values…
Tim Kochetkov
  • 149
  • 1
  • 11
2
votes
1 answer

Mypy type confusion with Union of Callable

I'm relatively new to Python type hinting and mypy and was wondering why the following code fails mypy verification. from typing import Callable, Union class A: a: int = 1 class B: b: int = 1 def foo(cb: Union[Callable[[A], None],…
2
votes
1 answer

How to understand the `callable` in the right way?

As per the document, which says: A Callable type is a type for which the INVOKE operation (used by, e.g., std::function, std::bind, and std::thread::thread) is applicable. This operation may be performed explicitly using the library function…
John
  • 2,963
  • 11
  • 33
2
votes
1 answer

How to understand "well formed when treated as an unevaluated operand"

As per the document, which says that[emphasis mine]: template struct is_invocable; Determines whether Fn can be invoked with the arguments ArgTypes.... Formally, determines whether INVOKE(declval(),…
John
  • 2,963
  • 11
  • 33
2
votes
2 answers

Are pointer to member functions not callable object

I am reading C++ Primer 5th edition and there I came across the following statement: As a result, unlike ordinary function pointers, a pointer to a member is not a callable object; these pointers do not support the function-call operator. So my…
Jason
  • 36,170
  • 5
  • 26
  • 60
2
votes
0 answers
2
votes
4 answers

How to get information from several threads? Java

I want to start several callable threads in the same time(in loop), and want to return some information from everyone in main thread. How to realise this?
Divers
  • 9,531
  • 7
  • 45
  • 88
2
votes
2 answers

I am trying to run two functions onLoad, one needs to run first so the second one can populate a boxlist, however, the second one doesn't get thearray

I have two functions that I am trying to run when I load the page. dataRetrieve() gets the data from a firebase collection. populate() is supposed to populate a boxlist with the entries retrieved from dataRetrieve(). The main problem is that it…
2
votes
1 answer

In Julia, can you specify the parameters and return value of a callable function argument?

In Python, you can specify the arguments and return value for a callable being passed to another function (reference). For example: def foo( bar: Callable[[str],int], # a function that takes a string as an argument and returns an int baz:…
A Poor
  • 856
  • 10
  • 26
2
votes
3 answers

FutureTask get vs run, task never finishes

I am learning Callables and decided to make a very simple program. The problem is that the Thread is blocked when I call getFutureTask(); Thread.State: TIMED_WAITING (on object monitor) Could you please tell me why is it so and why does my program…
user15204218
2
votes
1 answer

No image show up on for loop

I made a function which creates plotly figure and applied for loop on it. def doplot(df, somenumber): forplot = some_preprocessing_function(df,somenumber) fig = px.line(forplot, x = 'STATS_DTTM', y = "FRME_DISTRICT_CODE",color = "FRME_MEDIA",…
2
votes
3 answers

How to call a method in parent class inside of Lambda function in Java?

I was trying to write the following piece of code, but the error happened on line return super.getAge("Jack"); It showed "The method getAge() is undefined for the type Object". I guess the "super" keyword is not identified here. Does anyone have any…
Gaoyang
  • 41
  • 1
  • 5
2
votes
3 answers

C++17 How to save a generic callable for later use

I want to save a generic callable with its state for later use. Please see the example code bellow. I could probably use std::function or std::bind to achieve this but I do not know what is best. Also please note that in the main() of the example…
pettitpeon
  • 87
  • 4
2
votes
1 answer

How to see which thread(name) was executed from a future object

The code below is what I make an instance of an submit to executor service and its result is what i store in a future object. Is there any way I can see the name of the thread that gave the result from the future object. For example, if thread 1…
REEEEEE
  • 23
  • 5