Async service call - blocked. Why?

36 views
Skip to first unread message

wDevil

unread,
Nov 4, 2009, 4:01:09 PM11/4/09
to rpyc
def start_task(city, host):
service = rpyc.connect(host,7150)
work_dir = service.root.get_work_dir()
run_servers[city] = host
async_function_obj = rpyc.async(service.root.raster('%s/data/%s'%
(work_dir, city),0,9,
done_callback, status_callback))
i=1
while i < len(servers):
server = servers.pop()
city = cities.pop()
start_task(city, server)
i +=1

Why in my code, this operation:
async_function_obj = rpyc.async(service.root.raster('%s/data/%s'%
(work_dir, city),0,9,
done_callback, status_callback))

blocking my script? Task was created only for first server. where I
was mistaken?
sorry for my english

tomer filiba

unread,
Nov 11, 2009, 9:14:30 AM11/11/09
to rp...@googlegroups.com
that's because you're using it wrong:

async_function_obj = rpyc.async(service.root.raster('%s/data/%s' % (work_dir, city), 0, 9, done_callback, status_callback))

what you've done here is not async -- it's sync. you invoke the function synchronously and then wrap the result with an async wrapper.

here's what you should be doing:

async_func = rpyc.async(service.root.raster)
res = async_func('%s/data/%s' % (work_dir, city), 0, 9)

now you have an AsyncResult object, which you can use to poll the progress of the async operation:
res.ready - whether the result has arrived or not
res.wait() - wait for the result to arrive
res.value - the value of the result (will block until the result arrives)
etc.



An NCO and a Gentleman

tahmmee

unread,
Jan 5, 2010, 9:17:27 PM1/5/10
to rpyc

Hmm, anyone know why the AsyncResult has to be polled in order to
produce a value? From the logs, my service doesn't do any work unless
I spam res.ready. semi-async it seems :(

For example, if the above service.root.raster function were to print
something or do some server side computation, you wouldn't see
anything happening on the server until a call was made to res.ready.

Any ideas why this is happening?


On Nov 11 2009, 6:14 am, tomer filiba <tomerfil...@gmail.com> wrote:
> that's because you're using it wrong:
> async_function_obj = rpyc.async(service.root.raster('%s/data/%s' %
> (work_dir, city), 0, 9, done_callback, status_callback))
>
> what you've done here is not async -- it's sync. you invoke the function
> synchronously and then wrap the result with an async wrapper.
>
> here's what you should be doing:
>
> async_func = rpyc.async(service.root.raster)
> res = async_func('%s/data/%s' % (work_dir, city), 0, 9)
>
> now you have an AsyncResult object, which you can use to poll the progress
> of the async operation:
> res.ready - whether the result has arrived or not
> res.wait() - wait for the result to arrive
> res.value - the value of the result (will block until the result arrives)
> etc.
>
> An NCO and a Gentleman
>

Reply all
Reply to author
Forward
0 new messages