SOBotics / Botpy

A python framework for creating chatbots on the StackExchange network.
Other
5 stars 1 forks source link

Get rid of threads #18

Open double-fault opened 5 years ago

double-fault commented 5 years ago

For some reason, threading in Python isn't really preferred (I never could understand why...). The BackgroundTaskManager currently uses threads to schedule and run various tasks simultaneously.

Since the code already exists, I don't plan on discarding it, but an option to not use threads would be rather nice. In such situations, an alternative function belonging to the Bot class will need to be called in an infinite loop, which will schedule the tasks using a simple check of elapsed time.

This change, along with a couple of bugfixes should be enough for version 1.

tripleee commented 5 years ago

ChatExchange uses threading anyway, so I really don't know if this makes sense. Perhaps if ChatExchange went async, it would make sense for us to follow suit.

(I'm certainly a threading skeptic, so I'm all for it in principle. No objection if we can lead the way; but I doubt our example could compel upstream to make large architectural changes.)

double-fault commented 5 years ago

@tripleee I've used threads quite a lot, and I usually don't see any problem with them, but switching away from threads in the BackgroundTaskManager will have other advantages, IMO.

Currently, every task has it's own thread, which could make it difficult to debug some situations. Plus, async should use a lot less memory than the current threading system.

This isn't very high on my priority list (whenever I actually get time..), since some other bugs exist which block some functionality. But, I guess, it could be something nice to have.