-
Notifications
You must be signed in to change notification settings - Fork 0
Don't serialize dcp objects #43
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
Changes from all commits
d6fa4fb
ff33bba
bb0faa8
211ad37
9585474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,8 +78,8 @@ def _before_exec(self, *args, **kwargs): | |
| serialized_input_data = [] | ||
| if len(self.serializers): | ||
| validate_serializers(self.serializers) | ||
| if hasattr(self.js_ref.jobInputData, 'js_ref') and dry.class_manager.reg.find_from_js_instance(self.js_ref.jobInputData.js_ref): | ||
| serialized_input_data = self.js_ref.jobInputData.js_ref | ||
| if hasattr(self.jobInputData, 'js_ref') and dry.class_manager.reg.find_from_js_instance(self.jobInputData.js_ref): | ||
| serialized_input_data = self.jobInputData.js_ref | ||
| elif isinstance(self.js_ref.jobInputData, list) or utils.instanceof(self.js_ref.jobInputData, pm.globalThis.Array): | ||
| for input_slice in self.js_ref.jobInputData: | ||
| # TODO - find better solution | ||
|
|
@@ -95,11 +95,8 @@ def _before_exec(self, *args, **kwargs): | |
| serialized_input_data.append(serialized_slice) | ||
| else: | ||
| serialized_input_data = self.js_ref.jobInputData | ||
| if hasattr(self.js_ref.jobArguments, 'js_ref') and dry.class_manager.reg.find_from_js_instance(self.js_ref.jobArguments.js_ref): | ||
| serialized_arguments = self.js_ref.jobArguments.js_ref | ||
| # if utils.instanceof(self.js_ref.jobArguments, pm.eval("globalThis.dcp.compute.RemoteDataSet")): | ||
| # convertToURL = pm.eval('(urlString) => new URL(urlString)') | ||
| # self.js_ref.jobArguments.forEach(lambda argument: serialized_arguments.append(convertToURL(argument))) | ||
| if hasattr(self.jobArguments, 'js_ref') and dry.class_manager.reg.find_from_js_instance(self.jobArguments.js_ref): | ||
| serialized_arguments = [self.jobArguments.js_ref] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks incorrect to me, doesn't this make serialized_arguments an array of array-likes when it should just be an array-like?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because line 143 on this file expects
This solution did seem a little fishy to me in some way, but I was getting the correct behaviour with single objects (such as There might be other cleaner more intuitive solutions than just slapping it in an array as well, my justification for this though was that the other branch of logic for job args always leaves
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this would work, for ex. [range(1,10)] is a list containing a range, it doesn't flatten the iterable Also we shouldn't be using Maybe we should instead use |
||
| else: | ||
| for argument in self.js_ref.jobArguments: | ||
| # TODO - find better solution | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from http.server import BaseHTTPRequestHandler, HTTPServer | ||
| import threading | ||
| import json | ||
|
|
||
| import dcp; dcp.init() | ||
|
|
||
| class SimpleHandler(BaseHTTPRequestHandler): | ||
| def do_GET(self): | ||
| path = int(self.path.strip('/')) | ||
| self.send_response(200) | ||
| self.send_header('Access-Control-Allow-Origin', '*') | ||
| self.send_header('Content-Type', 'application/json') | ||
| self.end_headers() | ||
| self.wfile.write(json.dumps(path).encode()) | ||
|
|
||
| #start http server on seperate thread | ||
| server_address = ("localhost", 12345) | ||
| httpd = HTTPServer(server_address, SimpleHandler) | ||
| print("Server running at http://localhost:12345") | ||
| server_thread = threading.Thread(target=httpd.serve_forever) | ||
| server_thread.daemon = True | ||
| server_thread.start() | ||
|
|
||
| def workfn(x,y): | ||
| import dcp | ||
| dcp.progress() | ||
| return x * y | ||
|
|
||
|
|
||
| # 'http://localhost:12345' must be added to a Worker's allowed origins for slices to be completed | ||
| # run worker.originManager.add('http://localhost:12345', null, null) in the console, or edit the worker config | ||
| # On the public group the job will encounter many errors since workers by default can't access that URL | ||
| my_rdp = dcp.compute.RemoteDataPattern('http://localhost:12345/{slice}',5) | ||
|
JosephAcernese marked this conversation as resolved.
|
||
| my_rds = dcp.compute.RemoteDataSet('http://localhost:12345/2') | ||
|
|
||
| my_j = dcp.compute_for(my_rdp, workfn, my_rds) | ||
|
|
||
|
|
||
| # add event listeners | ||
| my_j.on('readystatechange', print) | ||
| my_j.on('result', print) | ||
| my_j.on('error', print) | ||
|
|
||
| @my_j.on('accepted') | ||
| def accepted_handler(ev): | ||
| print(f"jobid = {my_j.id}") | ||
|
|
||
| my_j.public.name = 'simple bifrost2 remote data pattern example' | ||
|
|
||
| my_j.exec() | ||
| res = my_j.wait() | ||
|
|
||
| print(">>>>>>>>>>>>>>>>>>>>>>>>>> RESULTS ARE IN") | ||
| print(res) | ||
Uh oh!
There was an error while loading. Please reload this page.