Clean up a little bit, rename erpc 'execute', but still keep a binding for erpc
This commit is contained in:
@@ -17,22 +17,24 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, socket, time, threading
|
import os, threading
|
||||||
import Queue
|
import Queue
|
||||||
|
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from Queue import Empty, Queue
|
from Queue import Empty, Queue
|
||||||
|
|
||||||
from eventlet import api, coros, httpc, httpd, util, greenio
|
from eventlet import api, coros, httpc, httpd, greenio
|
||||||
from eventlet.api import trampoline, get_hub
|
from eventlet.api import trampoline, get_hub
|
||||||
|
|
||||||
_rpipe, _wpipe = os.pipe()
|
_rpipe, _wpipe = os.pipe()
|
||||||
_rfile = os.fdopen(_rpipe,"r",0)
|
_rfile = os.fdopen(_rpipe,"r",0)
|
||||||
_wrap_rfile = greenio.GreenPipe(_rfile)
|
## Work whether or not wrap_pipe_with_coroutine_pipe was called
|
||||||
util.set_nonblocking(_rfile)
|
if not isinstance(_rfile, greenio.GreenPipe):
|
||||||
|
_rfile = greenio.GreenPipe(_rfile)
|
||||||
|
|
||||||
|
|
||||||
def _signal_t2e():
|
def _signal_t2e():
|
||||||
nwritten = os.write(_wpipe,' ')
|
nwritten = greenio.__original_write__(_wpipe,' ')
|
||||||
|
|
||||||
_reqq = Queue(maxsize=-1)
|
_reqq = Queue(maxsize=-1)
|
||||||
_rspq = Queue(maxsize=-1)
|
_rspq = Queue(maxsize=-1)
|
||||||
@@ -79,11 +81,18 @@ def erecv(e):
|
|||||||
raise e
|
raise e
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def erpc(meth,*args, **kwargs):
|
def execute(meth,*args, **kwargs):
|
||||||
|
"""Execute method in a thread, blocking the current
|
||||||
|
coroutine until the method completes.
|
||||||
|
"""
|
||||||
e = esend(meth,*args,**kwargs)
|
e = esend(meth,*args,**kwargs)
|
||||||
rv = erecv(e)
|
rv = erecv(e)
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
## TODO deprecate
|
||||||
|
erpc = execute
|
||||||
|
|
||||||
|
|
||||||
class Proxy(object):
|
class Proxy(object):
|
||||||
""" a simple proxy-wrapper of any object that comes with a methods-only interface,
|
""" a simple proxy-wrapper of any object that comes with a methods-only interface,
|
||||||
in order to forward every method invocation onto a thread in the native-thread pool.
|
in order to forward every method invocation onto a thread in the native-thread pool.
|
||||||
@@ -102,9 +111,9 @@ class Proxy(object):
|
|||||||
if kwargs.pop('nonblocking',False):
|
if kwargs.pop('nonblocking',False):
|
||||||
rv = f(*args, **kwargs)
|
rv = f(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
rv = erpc(f,*args,**kwargs)
|
rv = execute(f,*args,**kwargs)
|
||||||
if type(rv) in self._autowrap:
|
if type(rv) in self._autowrap:
|
||||||
return Proxy(rv)
|
return Proxy(rv, self._autowrap)
|
||||||
else:
|
else:
|
||||||
return rv
|
return rv
|
||||||
return doit
|
return doit
|
||||||
|
Reference in New Issue
Block a user