Beispiel #1
0
    def initialize_person(self, u, idx):
        """
        This function creates and initializes an agent with the proper parameters for \
        simulation.

        More specifically, the function does

        #. creates the agent
        #. initializes the agent's parameters to the respective values in :attr:`params`

        :param universe.Universe u: the universe the agent will reside in
        :param int idx: the index of the agent within the household

        :return p: the agent
        :rtype: singleton.Singleton
        """

        # create the person
        p = singleton.Singleton(u.home, u.clock, u.schedule)

        # set person to have relevant parameters
        p.set(self.params, idx)

        # initialize the person
        p.location.local = location.HOME

        # set the state to idle
        p.state.stats = state.IDLE

        # set the state's start time and end time to the current time [univeral time]
        p.state.t_start = u.clock.t_univ
        p.state.t_end = u.clock.t_univ

        return p
Beispiel #2
0
def main():
    """
    Enter point
    """
    sys.stdout.write("\x1b]0;poezio\x07")
    sys.stdout.flush()
    import config
    config_path = config.check_create_config_dir()
    config.run_cmdline_args(config_path)
    config.create_global_config()
    config.check_create_log_dir()
    config.check_create_cache_dir()
    config.setup_logging()
    config.post_logging_setup()

    from config import options

    import theming
    theming.update_themes_dir()

    import logger
    logger.create_logger()

    import roster
    roster.create_roster()

    import core

    log = logging.getLogger('')

    signal.signal(signal.SIGINT, signal.SIG_IGN)  # ignore ctrl-c
    cocore = singleton.Singleton(core.Core)
    signal.signal(signal.SIGUSR1, cocore.sigusr_handler)  # reload the config
    signal.signal(signal.SIGHUP, cocore.exit_from_signal)
    signal.signal(signal.SIGTERM, cocore.exit_from_signal)
    if options.debug:
        cocore.debug = True
    cocore.start()

    # Warning: asyncio must always be imported after the config. Otherwise
    # the asyncio logger will not follow our configuration and won't write
    # the tracebacks in the correct file, etc
    import asyncio
    loop = asyncio.get_event_loop()

    loop.add_reader(sys.stdin, cocore.on_input_readable)
    loop.add_signal_handler(signal.SIGWINCH, cocore.sigwinch_handler)
    cocore.xmpp.start()
    loop.run_forever()
    # We reach this point only when loop.stop() is called
    try:
        cocore.reset_curses()
    except:
        pass
Beispiel #3
0
    def __init__(self, hhld_params):

        # Scenario constructor
        Scenario.__init__(self, hhld_params)

        # scenario identifier
        self.id = SOLO

        # create a single person
        sam = singleton.Singleton(self.u.home, self.u.clock, self.u.schedule)
        sam.set(self.params, idx=0)

        # add Single Sam to the universe
        self.u.people.append(sam)

        return
Beispiel #4
0
    def __init__(self, hhld_params):

        Scenario.__init__(self, hhld_params)

        # scenario identifier
        self.id = DUO

        # create Single Sam(s) and add them to the universe
        for i in np.arange(self.params.num_people):
            sam = singleton.Singleton(self.u.home, self.u.clock,
                                      self.u.num_sample_points)
            sam.set(self.params, idx=i)
            self.u.people.append(sam)

        # testing: changing the max occupancy of the bed
        # this should cause an activity conflict when it comes to sleeping
        self.u.home.assets['bed'].max_users = 1

        return
Beispiel #5
0
 def left_tab_win(self):
     if not Tab.tab_core:
         Tab.tab_core = singleton.Singleton(core.Core)
     return Tab.tab_core.left_tab_win
Beispiel #6
0
 def core(self):
     if not Tab.tab_core:
         Tab.tab_core = singleton.Singleton(core.Core)
     return Tab.tab_core
Beispiel #7
0
 def test_singleton_acquire(self):
     f = singleton.Singleton(THIS_DIR)
     try:
         f.acquire()
     finally:
         f.release()
Beispiel #8
0
from utils import net
from utils import on_error
from utils import subprocess42
from utils import zip_package

# Used to opportunistically set the error handler to notify the server when the
# process exits due to an exception.
_ERROR_HANDLER_WAS_REGISTERED = False

# Set to the zip's name containing this file. This is set to the absolute path
# to swarming_bot.zip when run as part of swarming_bot.zip. This value is
# overriden in unit tests.
THIS_FILE = os.path.abspath(zip_package.get_main_script_path())

# The singleton, initially unset.
SINGLETON = singleton.Singleton(os.path.dirname(THIS_FILE))

### bot_config handler part.


def _in_load_test_mode():
    """Returns True if the default values should be used instead of the server
  provided bot_config.py.

  This also disables server telling the bot to restart.
  """
    return os.environ.get('SWARMING_LOAD_TEST') == '1'


def get_dimensions(botobj):
    """Returns bot_config.py's get_attributes() dict."""
Beispiel #9
0
 def core(self):
     if not Win._win_core:
         Win._win_core = singleton.Singleton(core.Core)
     return Win._win_core
Beispiel #10
0
import singleton

## generate  instance
print(singleton.Singleton.get_instance())
print(singleton.Singleton.get_instance())
print(singleton.Singleton.get_instance())
print(singleton.Singleton.get_instance())

## Raise: NotImplementedError

try:
    # NotImplementederror
    singleton.Singleton()
    # 1/0 other error
except (NotImplementedError) as e:
    print(e)
except:
    print('other Error')