[ 
https://issues.apache.org/jira/browse/THRIFT-2366?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13902782#comment-13902782
 ] 

Jens Geyer edited comment on THRIFT-2366 at 2/16/14 7:02 PM:
-------------------------------------------------------------

Short sketch/idea how it could work:
{code}
outer code
- setup a service client using stream transport
- call service client's xxx-send() function 
- pass stream/string data to inner module via dedicated function call
  - create processor instance
  - pass stream data as input, provide another stream for output data
    - call to inner code
  - return output stream/string data to outer module
- setup a service client using stream transport
- call service client's xxx-recv() function 
- return the data
{code}

I have already used approx. 75% of the pieces outlined above with Delphi and C# 
and I'm positive that the rest could work out as well (the swiss army knife 
again). Can't say much about how the Python code supports that today, or what 
needs to be done to achieve that with Python. 

The easier way would be as follows (note there is no interface at all):

{code}
outer code
- setup a service client using stream transport
- serialize args structure (e.g. union, to support different calls)
- pass stream/string data to inner module via dedicated function call
  - deserialize args
    - call to inner code
  - serialize output struct (again, union to ...)
  - return stream/string to outer module
- deserialize the data
- return the data
{code}



was (Author: jensg):
Short sketch/idea how it could work:
{code}
outer code
- setup a service client using stream transport
- call service client's xxx-send() function 
- pass stream data to inner module via dedicated function call
  - create processor instance
  - pass stream data as input, provide another stream for output data
    - call to inner code
  - return output stream data
- setup a service client using stream transport
- call service client's xxx-recv() function 
- return the data
{code}

I have already used approx. 75% of the pieces outlined above with Delphi and C# 
and I'm positive that the rest could work out as well (the swiss army knife 
again). Can't say much about how the Python code supports that today, or what 
needs to be done to achieve that with Python. 


> Running Thrift in a single process / as a foreign function interface
> --------------------------------------------------------------------
>
>                 Key: THRIFT-2366
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2366
>             Project: Thrift
>          Issue Type: Improvement
>            Reporter: Eric Christiansen
>
> I propose Thrift be enhanced by allowing the server and client to exist in 
> the same thread.
> The user semantics would be similar to foreign function interfaces, such as 
> those generated by SWIG.
> Please see this SO question: 
> http://stackoverflow.com/questions/21211749/running-apache-thrift-in-a-single-process-as-a-foreign-function-interface
> Use case 1:
> Bob writes a CLI Python app that depends on C++ code.
> His users integrate his app into shell scripts, and are happy they don't have 
> to worry about starting and stopping a Thrift server.
> Use case 2:
> Alice is an iOS developer who wants to combine Haskell and C.
> Forking processes isn't allowed in iOS, so before she couldn't start a Thrift 
> server and get the desired combination.
> But now everything can live in a single thread, so she gets her polyglot 
> programming.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to