Delay/Suspend event propagation?

16 views
Skip to first unread message

matias sm

unread,
Aug 7, 2015, 5:40:04 AM8/7/15
to circuits
Hi, I'm migrating my project to using circuits framework because I think it would simplify it and ease development of many new features I want to add.

The project does lots of file processing (I/O) so I decided to use Workers to avoid blocking the execution of other events. The difficulty I'm facing is that while a Component needs to process a file, I would need to suspend/delay the event which fired that processing so it doesn't get further handled until the processing is finished.

I can't stop() the event and fire a new one because that may trigger the execution of handlers that already handled the event.

Some ascii art to (hopefully) clarify a little more:
-- event --> Handler1
                  |---> Handler 2 - task -> Worker
                           |-> <delay> ------>| (finish work)
                                              |-> Handler 3

Is there any way of accomplishing what I need? Any (better) alternative for handling my use case?

Thank you for your insights!

James Mills

unread,
Aug 7, 2015, 5:45:26 AM8/7/15
to circuit...@googlegroups.com
I think you just want to "listen" to the task_completed
event.

e.g:

(circuits)
prologic@daisy
Fri Aug 07 19:47:35 
~/circuits
$ python
Python 2.7.9 (default, Mar 19 2015, 22:32:11) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import sleep
>>> from circuits import task, Event, Debugger, Manager, Worker
>>> def f():
...     sleep(3)
...     return "Hello!"
... 
>>> m = Manager() + Debugger() + Worker(process=True)
>>> m.start()
<registered[*] (<Debugger/* 1079:Manager (queued=0) [S]>, <Manager/ 1079:Manager (queued=3) [R]> )>(<Thread(Manager, started daemon 140630248388352)>, None)
>>> 
<registered[worker] (<Worker/worker 1079:Manager (queued=0) [S]>, <Manager/ 1079:Manager (queued=2) [R]> )>
<started[*] (<Manager/ 1079:Manager (queued=1) [R]> )>

>>> x = m.fire(task(f))
>>> <task[*] (<function f at 0x7fe716eb5de8> )>

>>> <task_success[*] (<task[*] (<function f at 0x7fe716eb5de8> )>, 'Hello!' )>

>>> task.complete = True
>>> y = m.fire(task(f))
>>> <task[*] (<function f at 0x7fe716eb5de8> )>

>>> <task_success[*] (<task[*] (<function f at 0x7fe716eb5de8> )>, 'Hello!' )>
<task_complete[*] (<task[*] (<function f at 0x7fe716eb5de8> )>, 'Hello!' )>


--
You received this message because you are subscribed to the Google Groups "circuits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to circuits-user...@googlegroups.com.
To post to this group, send email to circuit...@googlegroups.com.
Visit this group at http://groups.google.com/group/circuits-users.
For more options, visit https://groups.google.com/d/optout.

matias sm

unread,
Aug 7, 2015, 6:45:03 PM8/7/15
to circuits
Thank you for the answer! I posted the same question in SO (and you answered it there too) so I think it would be better to follow up in there (so it can reach more people), if that is ok with you.

James Mills

unread,
Aug 7, 2015, 7:27:10 PM8/7/15
to circuit...@googlegroups.com
Perfectly fine by me :) And thanks for posting it to SO too!

cheers
James
Reply all
Reply to author
Forward
0 new messages