callable

Function to make functions callable doesn't work properly [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 11:58:00
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I'm having the problem of a button executing its' command when it's created. To stop this I have got a function, which can stop this behavior This is the function which makes functions callable without being executed while creating my button. Usually it works fine but with some functions it seems

Shutdown ExecutorService when no task has been submitted for a given time

瘦欲@ 提交于 2019-12-11 10:25:17
问题 I'm using an ExecutorService to call a service which basically connects to an application (local or remote via SSH), and allows to send commands to it and get its output. So, the Thread created by the ExecutorService is waiting for user input, and this input is then processed as a task through an implementation of the call method, which returns the output and looks like this: @Override public String call() throws Exception { write(command); return readResult(); } I would like to stop the

Get input/output type of callable

廉价感情. 提交于 2019-12-10 23:08:31
问题 I have the following problem: template<typename Func, typename T_in = /*input type of Func */, typename T_out = /*output type of Func */> std::vector<T_out> foo( Func f, const std::vector<T_in>& input) { std::vector<T_out> res( input.size() ); for( size_t i = 0 ; i < input.size() ; ++i ) res[ i ] = f( input[ i ] ); return res; } int main() { // example for f(x) = x*x std::vector<float> input = { /* ... */ }; auto res = foo( [](float in){ return in*in; }, input ); return 0; } As you can see

Why am I getting a NullPointerException when fetching values from Futures?

霸气de小男生 提交于 2019-12-10 21:07:16
问题 I'm using and ExecutorService to concurrently run some Callables . Here's a simplified version of my code: ArrayList<Book> objResults = new ArrayList<Book>(); ExecutorService esrExecutor = Executors.newFixedThreadPool(2); Set<Callable<ArrayList<Book>>> setCallables = new HashSet<Callable<ArrayList<Book>>>(); setCallables.add(new Callable<ArrayList<Book>>() { public ArrayList<Book> call() throws Exception { ArrayList<Book> objAmazonResults = new ArrayList<Book>(); try { Amazon objAmazon = new

Using callable(x) vs. hasattr(x, “__call__”)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 03:42:08
问题 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 just using try/except around an attempted call. I've tested items that are callable (a class and a function), using timeit with 100,000 iterations; in both cases using callable takes only about 75% of the time of checking for the attribute. When

Unit test succeeds in debug mode but fails when running it normally

自古美人都是妖i 提交于 2019-12-10 01:56:46
问题 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; @Override public void setUp() { numThreads = 5; pool = Executors.newFixedThreadPool(numThreads); } class TaskChecksForInterruptedBit implements Callable<String> { @Override public String call() throws Exception { interruptedBitSet = false; while (!Thread

How to send a function to a remote Pyro object

ぐ巨炮叔叔 提交于 2019-12-09 18:58:23
问题 I am trying to set up some code using Pyro to process python code functions on a remote host and get results back. After starting the name server, i would execute this code on the remote host (actually still on localhost): import Pyro4 class Server(object): def evaluate(self, func, args): return func(*args) def main(): server = Server() Pyro4.Daemon.serveSimple( { server: "server" }, ns=True) if __name__ == '__main__': main() On the client side i have this code, which is an example of the

How to make Callable wait till execution?

纵饮孤独 提交于 2019-12-08 12:13:34
问题 I have One Callable which I invoked using FutureTask<Integer> task = new FutureTask<Integer>(new MyCallable(name, type)); pool = Executors.newSingleThreadExecutor(); pool.submit(task); I want to know Is execution is continue after pool.submit(task) or It will wait for callable to complete its execution? In short I just want to know is there any method like thread.join() for Callable? 回答1: ... is there any method like thread.join() for Callable? The pool.submit(callable) method returns a

Check if callable can receive class as parameter in php

痴心易碎 提交于 2019-12-08 10:58:17
问题 I have a callable $f and I would like to know if it can receive an instance of a certain class Foo as input. At the moment I'm doing something like try { $f($foo); } catch (\TypeError $e) { throw new \InvalidArgumentException('The provided function can not evaluate inputs of this type'); } Is there a way to check this WITHOUT actually invoking the callable? Maybe with reflection or some other dark magic? 回答1: If you want to be able to reflect any kind of callable, you'll need to wrap up the

How to terminate CXF webservice call within Callable upon Future cancellation

南楼画角 提交于 2019-12-08 01:20:40
问题 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 through CXF generated code.. These services all contribute different information towards a single set of information I'm using for my project. The services however can