Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Added isawaitable function and deprecated is_async which will be remo…
Browse files Browse the repository at this point in the history
…ved in version 1.2. Issue #203 #release-note=core
  • Loading branch information
lsbardel committed Feb 24, 2016
1 parent bc6e04d commit 6a2f9e4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
13 changes: 13 additions & 0 deletions docs/source/acknowledgment.md
@@ -0,0 +1,13 @@
This is a list of modules and snipped of codes taken from the wonderful
python open-source community. In order of inclusion into pulsar:

* Python Http parser from [benoitc http-parser](http-parser: https://github.com/benoitc/http-parser)
* Autoreload utility [d6f0abf](https://github.com/quantmind/pulsar/commit/d6f0abf99bb4f539101f3badadba3d027eb1e295)
```
# Autoreloading launcher.
# Borrowed from Peter Hunt and the CherryPy project (http://www.cherrypy.org).
# Some taken from Ian Bicking's Paste (http://pythonpaste.org/).
#
# Portions copyright (c) 2004, CherryPy Team (team@cherrypy.org)
# All rights reserved.
```
4 changes: 2 additions & 2 deletions pulsar/apps/wsgi/middleware.py
Expand Up @@ -52,7 +52,7 @@
from functools import wraps

import pulsar
from pulsar import is_async, task, get_event_loop
from pulsar import isawaitable, task, get_event_loop
from pulsar.utils.httpurl import BytesIO

from .auth import parse_authorization_header
Expand Down Expand Up @@ -103,7 +103,7 @@ def wait_for_body_middleware(environ, start_response=None):
if environ['wsgi.input']:
stream = environ['wsgi.input']
chunk = stream.read()
if is_async(chunk):
if isawaitable(chunk):
chunk = yield from chunk
environ['wsgi.input'] = BytesIO(chunk)

Expand Down
29 changes: 19 additions & 10 deletions pulsar/async/access.py
@@ -1,20 +1,25 @@
import os
import threading
import logging
import asyncio
import warnings
from collections import OrderedDict
from threading import current_thread
import asyncio

from asyncio import iscoroutine, coroutine
from asyncio import iscoroutine, coroutine, Future

from pulsar.utils.config import Global
from pulsar.utils.system import current_process

try:
from asyncio import ensure_future
from inspect import isawaitable
except ImportError: # pragma nocover
ensure_future = asyncio.async

def isawaitable(c):
return isinstance(c, Future) or iscoroutine(c)


__all__ = ['get_event_loop',
'new_event_loop',
Expand All @@ -30,31 +35,35 @@
'Future',
'reraise',
'coroutine',
'is_async',
'isawaitable',
'ensure_future',
'CANCELLED_ERRORS']
'CANCELLED_ERRORS',
# Deprecated
'is_async']


_EVENT_LOOP_CLASSES = (asyncio.AbstractEventLoop,)
CANCELLED_ERRORS = (asyncio.CancelledError,)


def is_async(x): # pragma nocover
# TODO: remove in pulsar 1.2
warnings.warn("pulsar.is_async is deprecated and will be removed in "
"pulsar 1.2, use pulsar.isawaitable instead",
SyntaxWarning)
return isawaitable(x)


def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value

Future = asyncio.Future


def isfuture(x):
return isinstance(x, Future)


def is_async(c):
return isfuture(c) or iscoroutine(c)


LOGGER = logging.getLogger('pulsar')
NOTHING = object()
SELECTORS = OrderedDict()
Expand Down
4 changes: 2 additions & 2 deletions pulsar/async/mailbox.py
Expand Up @@ -60,7 +60,7 @@ def example():
from pulsar.utils.websocket import frame_parser
from pulsar.utils.string import gen_unique_id

from .access import get_actor, is_async
from .access import get_actor, isawaitable
from .futures import Future, task
from .proxy import actor_identity, get_proxy, get_command, ActorProxy
from .protocols import Protocol
Expand All @@ -81,7 +81,7 @@ def command_in_context(command, caller, target, args, kwargs, connection=None):
raise CommandError('unknown %s' % command)
request = CommandRequest(target, caller, connection)
result = cmnd(request, args, kwargs)
if is_async(result):
if isawaitable(result):
result = yield from result
return result

Expand Down
26 changes: 0 additions & 26 deletions pulsar/utils/autoreload.py
Expand Up @@ -4,32 +4,6 @@
#
# Portions copyright (c) 2004, CherryPy Team (team@cherrypy.org)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice,
# this list of conditions and the following disclaimer in the
# documentation
# and/or other materials provided with the distribution.
# * Neither the name of the CherryPy Team nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import signal
Expand Down

0 comments on commit 6a2f9e4

Please sign in to comment.