stop_poller removes poller entry from list, but thread continues to execute
I wrote a bot that uses start_poller to have a method called every N seconds. Under certain conditions, I call stop_poller() to stop the process, but while the entry gets removed from the current_pollers list, the thread continues to call my method. I am using a workaround where I cancel() the timer thread before calling start_poller() again.
Thanks for reporting this! Do you happen to have any simple reproduction code for us that we could use to debug this?
I'd be especially interested in seeing how you're cancelling the timer thread as well. We may be able to apply such an approach globally to fix this issue.
Ok, I found out some more regarding this issue. It only seems to happen when my callback does not take any arguments - if I pass an argument to the method in the start_poller and stop_poller commands, everything works fine. If it does not get an argument, I need to use my workaround code to stop the previous thread.
I wrote a simple chatbot plugin to demonstrate this, files are attached. Commenting/uncommenting the CALLBACK_ARGS_ENABLED and WORKAROUND_ENABLED values at the start of the timer.py file will toggle the behavior. Here is the output from runs I made, with different combinations of options:
Run 1: args disabled, workaround disabled:
2016/05/27 10:27:31 In timed_callback thread unknown 2016/05/27 10:27:41 In timed_callback thread unknown <--- original 10-second thread !interval 8 Calling stop_poller() Changing interval to 8 2016/05/27 10:27:51 In timed_callback thread unknown <--- this is the original thread 2016/05/27 10:27:55 In timed_callback thread unknown <--- this is the new thread 2016/05/27 10:28:01 In timed_callback thread unknown <--- #1 2016/05/27 10:28:03 In timed_callback thread unknown <--- #2 2016/05/27 10:28:11 In timed_callback thread unknown 2016/05/27 10:28:11 In timed_callback thread unknown
Run 2: args disabled, workaround enabled:
2016/05/27 10:25:29 In timed_callback thread unknown 2016/05/27 10:25:39 In timed_callback thread unknown 2016/05/27 10:25:49 In timed_callback thread unknown 2016/05/27 10:25:59 In timed_callback thread unknown 2016/05/27 10:26:09 In timed_callback thread unknown 2016/05/27 10:26:19 In timed_callback thread unknown <--- original thread !interval 7 Calling stop_poller() Changing interval to 7 2016/05/27 10:26:31 In timed_callback thread unknown <--- new thread 2016/05/27 10:26:38 In timed_callback thread unknown 2016/05/27 10:26:45 In timed_callback thread unknown 2016/05/27 10:26:52 In timed_callback thread unknown 2016/05/27 10:26:59 In timed_callback thread unknown
Run 3: args enabled, workaround disabled:
2016/05/27 10:29:50 In timed_callback thread #1 2016/05/27 10:30:00 In timed_callback thread #1 2016/05/27 10:30:10 In timed_callback thread #1 !2016/05/27 10:30:20 In timed_callback thread #1 <-- original thread interval 8 Calling stop_poller() Changing interval to 8 2016/05/27 10:30:30 In timed_callback thread #2 <--- new thread 2016/05/27 10:30:38 In timed_callback thread #2 2016/05/27 10:30:46 In timed_callback thread #2 2016/05/27 10:30:54 In timed_callback thread #2 2016/05/27 10:31:02 In timed_callback thread #2 2016/05/27 10:31:10 In timed_callback thread #2
This is really great info, thanks! Unfortunately I've been really busy so I haven't had the opportunity to look into this any further, but it's on the radar.
No worries, I have a workaround. All the other bits are working very well :)