[PEAK] issues with Trellis event loops and threads
Phillip J. Eby
pje at telecommunity.com
Mon Jul 21 10:21:48 EDT 2008
At 04:39 AM 7/21/2008 +0300, Sergey Schetinin wrote:
>There's a problem with using the trellis and activity module in a
>multithreaded app. There's a main loop thread with activity.EventLoop
>running and there's a rule that runs periodically by rescheduling
>itself (in my case it calls wx.ProgressBar.Pulse(), just to give you
>an example of why this could be a legitimate use). There's also a
>worker thread that initiates this process, but due to EventLoop and
>Time being context.Service this doesn't work as expected -- the
>dependency on _Timer instance (Time[0.1] for example) created from a
>worker thread doesn't schedule a recalculation.
>
>See test in attached file -- it should't hang up, but it does as
>do_update rule only runs once.
>
>I tried to fix it by restoring state from the main thread in the
>worker thread but it's rather non-trivial as the State instances seem
>to rely on a threadlocal data. If there's a proper way to do it, I'd
>be happy to learn what it is. Thanks a lot in advance.
The Trellis does not support inter-thread communication at this time;
each thread's cells must be 100% isolated from other threads, and
each thread needs its own, isolated EventLoop. You can, of course,
make a special eventloop class that communicates with a main
eventloop, if you need to. But you'd need to do it using a
Queue.Queue or some other safe inter-thread communication mechanism.
More information about the PEAK
mailing list