Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Start Tutorial - Finishing Issue #115

Open
DevPy129387 opened this issue Mar 7, 2024 · 0 comments
Open

Quick Start Tutorial - Finishing Issue #115

DevPy129387 opened this issue Mar 7, 2024 · 0 comments

Comments

@DevPy129387
Copy link

DevPy129387 commented Mar 7, 2024

  • SPADE version: 3.3.2
  • Python version: 3.11
  • Operating System: Windows 10

Description

I did the second example in the Quick Start section of the documentation (An agent with a behaviour). It is stated, that "this agent would go on counting forever until we press ctrl+C.".
But if I press Ctrl+C, the agent won't stop. It says "Keyboard interrupt received. Stopping SPADE..." but continues.

What I Did

import asyncio
import spade
from spade import wait_until_finished
from spade.agent import Agent
from spade.behaviour import CyclicBehaviour

class DummyAgent(Agent):
    class MyBehav(CyclicBehaviour):
        async def on_start(self):
            print("Starting behaviour . . .")
            self.counter = 0

        async def run(self):
            print("Counter: {}".format(self.counter))
            self.counter += 1
            await asyncio.sleep(1)

    async def setup(self):
        print("Agent starting . . .")
        b = self.MyBehav()
        self.add_behaviour(b)

async def main():
    dummy = DummyAgent("???", "???")
    await dummy.start()
    print("DummyAgent started. Check its console to see the output.")

    print("Wait until user interrupts with ctrl+C")
    await wait_until_finished(dummy)

if __name__ == "__main__":
    spade.run(main())

Output:

Agent starting . . .
DummyAgent started. Check its console to see the output.
Wait until user interrupts with ctrl+C
Starting behaviour . . .
Counter: 0
Counter: 1
Counter: 2
Counter: 3
Counter: 4
Keyboard interrupt received. Stopping SPADE...
Counter: 5
Counter: 6
Counter: 7
Counter: 8
Counter: 9
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant