TUDelft-CNS-ATM / bluesky

The open source air traffic simulator
GNU General Public License v3.0
342 stars 239 forks source link

Creating a server using bs.init #457

Closed Ellislee1 closed 7 months ago

Ellislee1 commented 1 year ago

Is there a proper way to create a visible server using the bs.init command I have the following and receive the attached error:

import bluesky as bs
from bluesky.simulation import ScreenIO

class ScreenDummy(ScreenIO):
    """
    Dummy class for the screen. Inherits from ScreenIO to make sure all the
    necessary methods are there. This class is there to reimplement the echo
    method so that console messages are printed.
    """

    def echo(self, text='', flags=0):
        """Just print echo messages"""
        print("BlueSky console:", text)

bs.init(mode='server', discoverable=True)

# initialize dummy screen
bs.scr = ScreenDummy()
Using Python-based geo functions
Warning: RTree could not be loaded. areafilter get_intersecting and get_knearest won't work
Reading config from C:\Users\Ellis\bluesky\settings.cfg
Reading magnetic variation data
Attempt to reimplement HELP from <function showhelp at 0x0000024B5139BBA0> to <function showhelp at 0x0000024B53473100>
Traceback (most recent call last):
  File "c:\Users\Ellis\Documents\Research\one-shot-strategic-deconfliction\src\Simulation\BlueSkySim.py", line 18, in <module>
    bs.init(mode='server')
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\__init__.py", line 118, in init
    stack.init(mode)
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\__init__.py", line 17, in init
    import bluesky.stack.clientstack as clientstack
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\clientstack.py", line 67, in <module>
    @commandgroup(name='HELP', aliases=('?',))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    bs.init(mode='server', discoverable=True)
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\__init__.py", line 118, in init
    stack.init(mode)
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\__init__.py", line 17, in init
    import bluesky.stack.clientstack as clientstack
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\clientstack.py", line 67, in <module>    @commandgroup(name='HELP', aliases=('?',))
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\cmdparser.py", line 242, in deco
    cls.addcommand(fun, parent, **kwargs)
  File "C:\Users\Ellis\AppData\Local\Programs\Python\Python311\Lib\site-packages\bluesky\stack\cmdparser.py", line 38, in addcommand
    raise TypeError(f'Error reimplementing {name}: '
TypeError: Error reimplementing HELP: A Command cannot be reimplemented as a CommandGroup
jooste commented 1 year ago

Hi @Ellislee1,

If you really want, you could do the following:

import bluesky as bs

bs.init(mode='server', discoverable=True)
bs.server.run()

I can't think of a use case, however, where you need a custom way to start the bluesky server, instead of starting the main script with --headless. What is it that you are trying to achieve?