Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pierre Paleo
sidi
Commits
204ba9ee
Commit
204ba9ee
authored
Jan 21, 2019
by
Pierre Paleo
Browse files
Add demo_remoteclass
parent
01a31b84
Changes
1
Hide whitespace changes
Inline
Side-by-side
sidi/test/demo_remoteclass.py
View file @
204ba9ee
...
...
@@ -3,44 +3,50 @@ from threading import Thread
from
distributed
import
Client
from
sidi.scheduler
import
spawn_scheduler_process
from
sidi.worker
import
DaskWorker
from
sidi.remote
import
RemoteClass
from
time
import
sleep
from
sidi.remote
import
RemoteClass
from
time
import
sleep
import
atexit
class
Dummy
(
object
):
def
__init__
(
self
,
a
=
1
):
self
.
a
=
a
class
Dummy
(
object
):
def
__init__
(
self
,
a
=
1
):
self
.
a
=
a
def
do_work
(
self
,
a
):
print
(
"[%d] Doing work"
%
os
.
getpid
())
sleep
(
a
)
return
a
+
1
def
do_work
(
self
,
a
):
print
(
"[%d] Doing work"
%
os
.
getpid
())
sleep
(
a
)
return
a
+
1
def
mycallback
(
fut
):
print
(
"callback time !"
)
def
cleanUp
(
P
,
W
):
print
(
"Stopping workers"
)
W
.
stop
()
sleep
(
1
)
print
(
"Stopping scheduler"
)
P
.
terminate
()
sleep
(
1
)
def
main
():
P
=
spawn_scheduler_process
(
addr
=
"tcp://127.0.0.1"
,
port
=
5455
)
W
=
DaskWorker
(
"tcp://127.0.0.1:5455"
,
nprocs
=
1
,
nthreads
=
1
)
T
=
Thread
(
target
=
W
.
start
)
T
.
start
()
cl
=
Client
(
"tcp://127.0.0.1:5455"
)
input
(
"Instantiate remote class ?"
)
RC
=
R
emote
C
lass
(
cl
,
Dummy
,
a
=
1
)
print
(
"...OK
\n\n
"
)
sleep
(
2
)
input
(
"Ready to submit..."
)
futures
=
RC
.
submit_task
(
"do_work"
,
callback
=
mycallback
,
method_args
=
(
1
,)
)
print
(
futures
)
return
P
,
W
P
=
spawn_scheduler_process
(
addr
=
"tcp://127.0.0.1"
,
port
=
5455
)
W
=
DaskWorker
(
"tcp://127.0.0.1:5455"
,
nprocs
=
1
,
nthreads
=
1
)
T
=
Thread
(
target
=
W
.
start
)
T
.
start
()
cl
=
Client
(
"tcp://127.0.0.1:5455"
)
atexit
.
register
(
cleanUp
,
P
,
W
)
input
(
"Instantiate r
emote
c
lass
?"
)
RC
=
RemoteClass
(
cl
,
Dummy
,
a
=
1
)
print
(
"...OK
\n\n
"
)
sleep
(
2
)
input
(
"Ready to submit..."
)
futures
=
RC
.
submit_task
(
"do_work"
,
callback
=
mycallback
,
method_args
=
(
1
,)
)
return
futures
if
__name__
==
"__main__"
:
try
:
P
,
W
=
main
()
finally
:
W
.
stop
()
P
.
terminate
()
\ No newline at end of file
futures
=
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment