Closed ryanstwrt closed 4 years ago
Yeah, your run_problem()
method takes control of the main thread, so the agent does not process incoming messages until it finishes the run_problem()
execution. That means, your Blackboard
is receiving the messages on time, only it does not process them on time.
You want to do that asynchronously.
An alternative (not recommended) would be to call bb.unsafe.run_problem()
. See the documentation on one-way, unsafe calls. This is not recommended since it is "unsafe", which means you will have two threads running concurrently. Python's GIL protects you, but better be sure!
So you may want to use timers instead:
# bb.run_problem()
bb.each(1, 'send_pub_trigger')
time.sleep(3)
ns.shutdown()
PS: if timers do not fit your purpose well, consider splitting your Blackboard agent in two: make one agent "active", which just sleeps and sends triggers. Then the other agent is completely reactive: it receives triggers and reacts to them by sending PUB messages. Once they are sent, its reaction is complete, so it goes back to listening to new incoming events. This way it will process the reply back from the agent on time.
Alternatively, you can safely execute tasks in parallel if you run bb.unsafe.run_task()
or bb.after(0, 'task')
, but in order to be safe you would need to communicate with the main thread using the loopback
socket, or another inproc
socket that you create. This is unfortunately not documented. If you want to contribute documentation on that, welcome! :blush:
Wonderful, that is definitely what I was missing! Thank you for the information. I think I might try this a couple of different ways to see which is most effective for my problem. If I end up using the last method you suggested, I'll be sure to write something up. Thanks again.
Closing this for now then. Feel free to comment/reopen if you need more help. :blush:
Hi, I'm using osbrain for creating a blackboard system with multiple agents, but I am running into some timing issues. I've created two proxy classes that are able to reproduce the error, they are posted below.
I am running into an issue with timing when I attempt to use the
run_problem
method inBlackboard
. Below is my attempt to run the method, where the output is posted belowInput
Output
We notice that both the blackboard publishes the trigger to our agent, however we do not get the
push
response (i.e.Writing Trigger Response
) from the agent until after both triggers are sent. The intended function should send the trigger viapublish
and receive thepush
response before the next trigger event is send out. However, I've noticed that if I perform this type of action outside of the Blackboard agent, I get the correct functionality. The loop below is essentially mimicking therun_problem
method.Input
Output
We notice that the trigger is sent by the
blackboard
, and immediately afterwards theKaBase
agent sends itspush
response. I imagine that I am missing something relating to the timing of sending/receiving messages. Any help would be appreciated. Thank you.-Ryan