python - Can Perspective Broker be used over stdio instead of TCP? -


i'm using twisted's perspective broker rmi between process , subprocess.

rather listen on tcp socket (such passing reactor.listentcp() instance of pbserverfactory) , have subprocess connect it, i'd prefer use subprocess's stdin , stdout.

i've found twisted.internet.stdio.standardio, if that's way go, i'm not sure how set up.

is feasible use pb on stdio instead of tcp? how?


wait, why?

the subprocess running untrusted code. it's sandboxed, needs able communicate parent process in limited ways. form of rmi far cleanest option specific use case, , pb has access model looks right. sandboxed process doesn't have -- , shouldn't need -- network access. rmi communication outside world, , piping through stdin/stdout seems clean way of doing business.

but if i'm not going right way, that's valid answer too.

using protocol pb between parent , child process on stdio-like connection has 2 pieces. 1 piece in child process, using file descriptors 0 , 1 communicate parent. other piece parent process, using whatever file descriptors correspond child's 0 , 1.

standardio first piece. still need second piece - that's ireactorprocess.spawnprocess.

however, newer endpoints apis better way access functionality.

the basics of endpoints client endpoint lets connect server without caring how connection established , server endpoint lets accept connections clients without caring how clients connecting.

there child process client endpoint , stdio server endpoint. means can write client like:

factory = pbclientfactory(...) d = factory.getrootobject() ...  clientendpoint.connect(factory) 

and server like:

factory = pbserverfactory(...) ... serverendpoint.listen(factory) 

and have client , server talk each other, haven't specified how talk each other yet. perhaps it's tcp or perhaps it's stdio.

then need pick right endpoints use. stick idea of communicating on stdio:

clientendpoint = processendpoint(reactor, "/path/to/child", ("argv",), ...) serverendpoint = standardioendpoint(reactor) 

if change mind later, switching - - tcp easy as:

clientendpoint = tcp4clientendpoint(reactor, "1.2.3.4", 12345) serverendpoint = tcp4serverendpoint(reactor, 12345) 

or can use plugin mechanism string descriptions of endpoints turn configuration instead:

clientendpoint = clientfromstring(reactor, options["client-endpoint"]) serverendpoint = serverfromstring(reactor, options["server-endpoint"]) 

where options["client-endpoint"] , options["server-endpoint"] strings "tcp:host=1.2.3.4:port=12345" , "tcp:port=12345".

for more, see complete endpoints howto.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -