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

Some exception handling added for minion.py #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions pydfs/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@ class exposed_Minion():
blocks = {}

def exposed_put(self,block_uuid,data,minions):
with open(DATA_DIR+str(block_uuid),'w') as f:
f.write(data)
if len(minions)>0:
self.forward(block_uuid,data,minions)
try:
with open(DATA_DIR+str(block_uuid),'w') as f:
f.write(data)
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
except:
print "Unexpected error:", sys.exc_info()[0]
if len(minions)>0:
self.forward(block_uuid,data,minions)


def exposed_get(self,block_uuid):
block_addr=DATA_DIR+str(block_uuid)
if not os.path.isfile(block_addr):
return None
with open(block_addr) as f:
return f.read()
try:
with open(block_addr) as f:
return f.read()
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
except: # handle other exceptions such as attribute errors
print "Unexpected error:", sys.exc_info()[0]

def forward(self,block_uuid,data,minions):
print "8888: forwaring to:"
Expand All @@ -39,6 +49,10 @@ def delete_block(self,uuid):
pass

if __name__ == "__main__":
if not os.path.isdir(DATA_DIR): os.mkdir(DATA_DIR)
try:
if not os.path.isdir(DATA_DIR): os.mkdir(DATA_DIR)
except OSError as e:
print "OS error({0}): {1}".format(e.errno, e.strerror)

t = ThreadedServer(MinionService, port = 8888)
t.start()
t.start()