Skip to content

Commit a2f2474

Browse files
authored
fix (#3542)
1 parent 37f8d53 commit a2f2474

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

poncho/src/poncho/wq_network_code.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def main():
4848
"port": s.getsockname()[1],
4949
}
5050
send_configuration(config)
51+
abs_working_dir = os.getcwd()
5152
while True:
5253
s.listen()
5354
conn, addr = s.accept()
@@ -72,7 +73,7 @@ def main():
7273
event = json.loads(event_str)
7374
# see if the user specified an execution method
7475
exec_method = event.get("remote_task_exec_method", None)
75-
os.chdir(f"t.{task_id}")
76+
os.chdir(os.path.join(abs_working_dir, f't.{task_id}'))
7677
if exec_method == "direct":
7778
response = json.dumps(globals()[function_name](event)).encode("utf-8")
7879
else:
@@ -102,8 +103,20 @@ def main():
102103
conn.sendall(size_msg.encode('utf-8'))
103104
# send response
104105
conn.sendall(response)
105-
os.chdir("..")
106106
break
107107
except Exception as e:
108108
print("Network function encountered exception ", str(e), file=sys.stderr)
109+
response = {
110+
'Result': f'network function encountered exception {e}',
111+
'Status Code': 500
112+
}
113+
response = json.dumps(response).encode('utf-8')
114+
response_size = len(response)
115+
size_msg = "{}\n".format(response_size)
116+
# send the size of response
117+
conn.sendall(size_msg.encode('utf-8'))
118+
# send response
119+
conn.sendall(response)
120+
finally:
121+
os.chdir(abs_working_dir)
109122
return 0

0 commit comments

Comments
 (0)