callback

How can I write a simple callback function?

How can I write a simple callback function? Question: I have this example code, trying to demonstrate using a callback function: def callback(a, b): print(‘Sum = {0}’.format(a+b)) def main(callback=None): print(‘Add any two digits.’) if callback != None: callback main(callback(1, 2)) I get this result: Sum = 3 Add any two digits. It seems that the …

Total answers: 7

Python tkinter text modified callback

Python tkinter text modified callback Question: In python 2.7, I am trying to get a callback every time something is changed in the Tkinter Text widget. The program uses multiple frames based on code found here: Switch between two frames in tkinter? The callback part is taken from the following example: http://code.activestate.com/recipes/464635-call-a-callback-when-a-tkintertext-is-modified/ Both codes work …

Total answers: 2

Who runs the callback when using apply_async method of a multiprocessing pool?

Who runs the callback when using apply_async method of a multiprocessing pool? Question: I’m trying to understand a little bit of what’s going on behind the scenes when using the apply_sync method of a multiprocessing pool. Who runs the callback method? Is it the main process that called apply_async? Let’s say I send out a …

Total answers: 1

Python alternative to Javascript function.bind()?

Python alternative to Javascript function.bind()? Question: In Javascript, one might write var ids = [‘item0’, ‘item1’, ‘item2’, ‘item3’]; // variable length function click_callback(number, event) { console.log(‘this is: ‘, number); } for (var k = 0; k < ids.length; k += 1) { document.getElementById(ids[k]).onclick = click_callback.bind(null, k); } So I can pass to the callback function …

Total answers: 1

A very simple multithreading parallel URL fetching (without queue)

A very simple multithreading parallel URL fetching (without queue) Question: I spent a whole day looking for the simplest possible multithreaded URL fetcher in Python, but most scripts I found are using queues or multiprocessing or complex libraries. Finally I wrote one myself, which I am reporting as an answer. Please feel free to suggest …

Total answers: 5

Is there any type for function in Cython?

Is there any type for function in Cython? Question: Is there any way to tell Cython compiler that param is function. Something like cpdef float calc_class_re(list data, func callback) Asked By: xander27 || Source Answers: Should be self-explanatory..? 🙂 # Define a new type for a function-type that accepts an integer and # a string, …

Total answers: 1

How to pass an argument to a function pointer parameter?

How to pass an argument to a function pointer parameter? Question: I only just started learning Python and found out that I can pass a function as the parameter of another function. Now if I call foo(bar()) it will not pass as a function pointer but the return value of the used function. Calling foo(bar) …

Total answers: 3

thread starts running before calling Thread.start

thread starts running before calling Thread.start Question: t1=threading.Thread(target=self.read()) print("something") t2=threading.Thread(target=self.runChecks(), args=(self,)) self.read runs indefinitely, so the program won’t ever reach the print line. How is this possible without calling t1.start()? (Even if I call that, it should start running and go on to the next line, shouldn’t it?) See also: What does it mean when …

Total answers: 1

pass callback from python to c++ using boost::python

pass callback from python to c++ using boost::python Question: I want to pass callback from my python code to c++ I want my code look something like this: In C++ : typedef void (*MyCallback_t) (CallbackInfo); class MyClass {… void setcallback(MyCallback_t cb); … } And to use it in python : import mylib def myCallback(mylib_CallbackInfo): … …

Total answers: 2

How to pass and run a callback method in Python

How to pass and run a callback method in Python Question: I have a Manager (main thread), that creates other Threads to handle various operations. I would like my Manager to be notified when a Thread it created ends (when run() method execution is finished). I know I could do it by checking the status …

Total answers: 3