callable

What is a "callable" in Python ?

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. What's more, using __init__ and __new__ lead to wonder what this bloody __call__ can be used...

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 illusrate: logger.info("sequentially executing all batches..."); for (TestExecutor executor : builder.getExecutors()) { logger.info("executing batch....

invokeAll() is not willing to acept a Collection<Callable<T>>

Hey I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads); class DocFeeder implements Callable<Boolean> {....} ... List<DocFeeder> list = new LinkedList<DocFeeder>(); list.add(new DocFeeder(1)); ... executor.invokeAll(list); The error msg is: The method invokeAll(Col...

How to schedule a Callable to run on a specific time?

I need to run a callable at a specific time of day. One way to do it is to calculate the timediff between now and the desired time , and to use the executor.scheduleAtFixedRate . Have a better idea? executor.scheduleAtFixedRate(command, TIMEDIFF(now,run_time), period, TimeUnit.SECONDS)) ...

How much logic is it "right" to put in a Callable?

I'm using callables quite often , and I've stubled upon a question that irritates me: Lets say that to run function foo() , one needs to do a couple of checks first. Should you 1. Insert the checks as part of the Callable : class A implements Callable<Long> { ... public Long call() { check1(); check2(); return (run());...

What is the difference between a function object and a callable object?

I recently saw the presentation about the changes in ECMAScript 5. And there was a slide with this statement: Function vs Callable typeof f === 'function' // → f is Callable ({}).toString.call(f) === '[object Function]' // → f is a Function Can anyone explain to me what the difference between Function and Ca...

How to terminate CXF webservice call within Callable upon Future cancellation

Edit This question has gone through a few iterations by now, so feel free to look through the revisions to see some background information on the history and things tried. I'm using a CompletionService together with an ExecutorService and a Callable, to concurrently call the a number of functions on a few different webservices throug...

Is there a way to have callable objects in Groovy?

If for example I have a class named A. Can I make an object be callable, just like Python does? For example : def myObject = new A() myObject() and that would call some object method. Can it be done? ...

PHP Callable Object as Object Member

I have a class Logger which, among other things has a method Log. As Log is the most common use of the Logger instance, I have wired __invoke to call Log Another class, "Site" contains a member "Log", an instance of Logger. Why would this work: $Log = $this->Log; $Log("Message"); But not this: $this->Log("Message"); The for...

Java: Parameterized Runnable

Standard Runnable interface has only non-parametrized run() method. There is also Callable<V> interface with call() method returning result of generic type. I need to pass generic parameter, something like this: interface MyRunnable<E> { public abstract void run(E reference); } Is there any standard interface for this purpose or I must...

Filling SWT table object using a separated thread class ...

Hi all I've got a code snippet by the swt team that does exactly what I need. However, there is a part I want to separate into another class, in particular, the whole inline stuff. In response to my former question, it has been suggested that Callable should be used in order to implement threaded objects. It is suggested to make use of ...

python function parameter evaluation model

I was looking at an article on Peter Norvig's website, where he's trying to answer the following question (this is not my question, btw) "Can I do the equivalent of (test ? result : alternative) in Python?" here's one of the options listed by him, def if_(test, result, alternative=None): "If test is true, 'do' result, else alterna...

Java - SwingWorker - problem

I am developing a Java Desktop Application. This app executes the same task public class MyTask implements Callable<MyObject> { in multiple thread simultaneously. Now, when a user clicks on a "start" button, I have created a SwingWorker myWorker and have executed it. Now, this myWorker creates multiple instances of MyTask and submits t...

On reference_wrapper and callable objects

Given the following callable object: struct callable : public std::unary_function <void, void> { void operator()() const { std::cout << "hello world" << std::endl; } }; a std::tr1::reference_wrapper<> calls through it: callable obj; std::tr1::ref(obj)(); Instead, when the operator() accepts an argument: s...

modifying a python callable so it calls before() , actual function then after()

Hello I am not sure if this is the best way to have before and after functions be called around a function f1(). class ba(object): def __init__(self, call, before, after): self.call = call self.before = before self.after = after def __call__(self, *args): self.before() r = self.call(*arg...