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

Remote Functions: continuous output (generators) #38

Open
psukys opened this issue Apr 26, 2018 · 2 comments
Open

Remote Functions: continuous output (generators) #38

psukys opened this issue Apr 26, 2018 · 2 comments

Comments

@psukys
Copy link
Contributor

psukys commented Apr 26, 2018

Currently trying to run a function that yields results (is a generator), doesn't work.

Remote function file foo.py:

def func():
    for i in range(100):
        yield i


if __name__ == '__channelexec__':
    for item in channel:
        channel.send(eval(item))

Execution code:

import remoto, logging, foo
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('otherhostname')
conn = remoto.Connection('otherhostname', logger=logger)
remote_foo = conn.import_module(foo)
foo.func()

Received output after executing last line in Execution code:
RuntimeError: DumpError: can't serialize <class 'generator'>

Is there a possible workflow for receiving continuous output from remote function?

@psukys psukys changed the title Remote Functions: passing generators Remote Functions: continuous output (generators) Apr 26, 2018
@alfredodeza
Copy link
Owner

Correct, this is a caveat of the serializing that execnet provides. If you need to continuously receive output, you should look at remoto/log.py and how it is used in remoto/process.py

@psukys
Copy link
Contributor Author

psukys commented Apr 27, 2018

I see, my general thoughts on this could be that the function/module could reuse channel to send back (instead of yield), but then ModuleExecute wrapper only does a single channel.receive(). I find it difficult to find consistent documentation on execnet's channel.receive functionality, but maybe it's possible to tell when channel is closed/finished?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants