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
794
votes
17 answers

TypeError: 'module' object is not callable

File "C:\Users\Administrator\Documents\Mibot\oops\blinkserv.py", line 82, in __init__ self.serv = socket(AF_INET,SOCK_STREAM) TypeError: 'module' object is not callable Why am I getting this error? I'm confused. How can I solve this error?
user551717
  • 8,217
  • 5
  • 18
  • 9
565
votes
14 answers

The difference between the Runnable and Callable interfaces in Java

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other?
Scottm
  • 7,004
  • 8
  • 32
  • 33
362
votes
13 answers

What is a "callable"?

Now that it's clear what a metaclass is, there is an associated concept that I use all the time without knowing what it really means. I suppose everybody made once a mistake with parenthesis, resulting in an "object is not callable" exception.…
Bite code
  • 578,959
  • 113
  • 301
  • 329
103
votes
20 answers

Why does code like `str = str(...)` cause a TypeError, but only the second time?

I have some code like: def example(parameter): global str str = str(parameter) print(str) example(1) example(2) The first call to example works, but then the second time around I get an error like: Traceback (most recent call last): …
P'sao
  • 2,946
  • 11
  • 39
  • 48
76
votes
3 answers

How to use Callable with void return type?

I am working on a project in which I have multiple interface and two Implementations classes which needs to implement these two interfaces. Suppose my first Interface is - public Interface interfaceA { public void abc() throws Exception; } And…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
64
votes
9 answers

TypeError: 'list' object is not callable while trying to access a list

I am trying to run this code where I have a list of lists. I need to add to inner lists, but I get the error TypeError: 'list' object is not callable. Can anyone tell me what am I doing wrong here. def createlists(): global maxchar global…
user487257
  • 1,071
  • 2
  • 9
  • 16
57
votes
6 answers

What's the difference between Future and FutureTask in Java?

Since use ExecutorService can submit a Callable task and return a Future, why need to use FutureTask to wrap Callable task and use the method execute? I feel they both do the same thing.
Hesey
  • 4,957
  • 6
  • 31
  • 31
50
votes
8 answers

Is there a way to take an argument in a callable method?

I have created a piece of code which takes an IP address (from main method in another class) and then loops through a range of IP addresses pinging each one as it goes. I have a GUI front end on this and it was crashing (hence why I've done the…
DMo
  • 591
  • 2
  • 6
  • 13
34
votes
3 answers

Difference between Spring MVC's @Async, DeferredResult and Callable

I've a long-running task defined in a Spring service. It is started by a Spring MVC controller. I want to start the service and return back an HttpResponse to the caller before the service ends. The service saves a file on file system at end. In…
Premier
  • 4,160
  • 6
  • 44
  • 58
29
votes
5 answers

Odd method call in java using a dot operator to access a generic list

I came across some advanced java code (advanced for me :) ) I need help understanding. In a class there is a nested class as below: private final class CoverageCRUDaoCallable implements Callable> { private final…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
29
votes
2 answers

When to use Spring @Async vs Callable controller (async controller, servlet 3)

I would like to know the general use case of using @Async and Servlet 3 asynchronous request implementation in Spring using Callable. As I understand, @Async is for making any method (specifically, any service method) execute…
devThoughts
  • 820
  • 1
  • 12
  • 18
27
votes
1 answer

Where to catch Exceptions thrown from Callable.call()

Possible Duplicate: Handling exceptions from Java ExecutorService tasks I use the ExecutorService from Java for coordinating Threads. For starting the threads I use pool = new ExecutorService(2); callableResults = pool.invokeAll(threads); To…
nano7
  • 2,455
  • 7
  • 35
  • 52
26
votes
7 answers

What is a callable object in C++?

I'm currently studying boost threads. And I came across that the thread class has a constructor that accepts callable objects. What are callable objects? class CallableClass { private: // Number of iterations int m_iterations; public: …
Xegara
  • 563
  • 2
  • 10
  • 23
25
votes
3 answers

How to pass a parameter to Scikit-Learn Keras model function

I have the following code, using Keras Scikit-Learn Wrapper, which work fine: from keras.models import Sequential from keras.layers import Dense from sklearn import datasets from keras.wrappers.scikit_learn import KerasClassifier from…
neversaint
  • 60,904
  • 137
  • 310
  • 477
23
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
  • 4,728
  • 8
  • 44
  • 68
1
2 3
50 51