I apologize if this is more about python threading than sublime, but I don’t know if sublime is somehow involved.
I have a job scheduled by threading.Timer to produce some data in 5 seconds. When the data is produced, it will call set on a threading.Event().
If the user issues a command that uses the data, it will wait for the event on the main thread. It should never take long, but the wait has a timeout of 20 sec just in case.
What I notice is that if the user issues a command during the 5 seconds (i.e., after the job that produces data has been scheduled but before it has been run), its wait will timeout. The reason for that is that the producer job (which has been scheduled to run within a few seconds) won’t run until just after the 20 sec timeout. It seems that the wait on the event is delaying the timer thread. I have all my threads loaded with prints, and I’m not doing any explicit locking that would explain this.
Is there something subtle going on that I’m not aware of?
Edit: The event wait() was a red herring. It seems that the problem is while my TextCommand’s run() method is running, all other threads are suspended. Is that true? I thought it was the wait() because that’s the only blocking call in my run() method, but even if I put a sleep in the run() method, that seems to prevent other threads from running. If it is true that TextCommands don’t allow a thread switch, then my idea of having the main thread wait for a result that is about to be produced by a different thread won’t work.