Melissa-AI / Melissa-Core

A lovely virtual assistant for OS X, Windows and Linux systems.
MIT License
491 stars 201 forks source link

Resolve Duplicity of Message #139

Closed tanay1337 closed 7 years ago

tanay1337 commented 7 years ago

When running python main.py, we get the message Loading profile data twice which needs to be resolved.

va6996 commented 7 years ago

On it

tanay1337 commented 7 years ago

This error is caused because profile.py is being called two times, once from here and then again from here, both of which are crucial.

One quick fix solution might be to delete this but I would like to hear others opinions for a better solution. Thoughts? @aniketk21 @vedmathai @rachmadaniHaryono

va6996 commented 7 years ago

is there really a need to import profile in start? I dont see any reference in start.py

tanay1337 commented 7 years ago

It is being used both at main.py and start.py. For your reference.

rachmadaniHaryono commented 7 years ago

here is another alternative, but more complex from than deleting that print line

# on profile.py
# - move load_profile func to new file name e.g. profile_loader.py (see the change belowe)
# .... import package
from profile_loader import load_profile
data = {}
if len(data) == 0:
    data = load_profile()
# on profile_loader.py
# .... import other package
from profile_populator import profile_populator
def load_profile(skip_message=False):
    if not skip_message:
        print("Loading profile data")
    if not os.path.isfile('profile.json'):
        profile_populator()
    profile_json = open('profile.json')
    data = json.load(profile_json, object_hook=jd.decode_dict)
    profile_json.close()
    return data

any from both file can import profile_loader and run load_profile(skip_message=True), to skip the message

so instead of profile.data, use data = load_profile(); data.

advantage of this

edit: add load_profile usage

edit2: not use function inside of function

tanay1337 commented 7 years ago

Yes, @rachmadaniHaryono's implementation seems a better solution instead of deleting that print statement. Feel free to pick this issue up guys!

rachmadaniHaryono commented 7 years ago

if anyone want to pick this, please check if there is any race condition of profile creation between start.py and main.py.

rachmadaniHaryono commented 7 years ago

anyone working on this? @aniketk21 @vedmathai @tanay1337 @rosskyl

tanay1337 commented 7 years ago

Go ahead @rachmadaniHaryono!

lakshmanaram commented 7 years ago

I would like to take up this issue @tanay1337 @rachmadaniHaryono

rachmadaniHaryono commented 7 years ago

OK @lakshmanaram, you can take it.