Commit a526a47e authored by Jason Madden's avatar Jason Madden

Make gevent.spawn_raw accept kwargs for consistency. Fixes #680.

parent 0ebe9d1e
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
SIGCHLD signal at the process level (although this may allow race SIGCHLD signal at the process level (although this may allow race
conditions with libev child watchers). Reported in :issue:`696` by conditions with libev child watchers). Reported in :issue:`696` by
Adam Ning. Adam Ning.
- :func:`gevent.spawn_raw` now accepts keyword arguments, as
previously (incorrectly) documented. Reported in :issue:`680` by Ron
Rothman.
- PyPy: PyPy 2.6.1 or later is now required (4.0.1 or later is recommended).
1.1rc1 (Nov 14, 2015) 1.1rc1 (Nov 14, 2015)
===================== =====================
......
...@@ -518,9 +518,8 @@ class loop(object): ...@@ -518,9 +518,8 @@ class loop(object):
if once: if once:
flags |= libev.EVRUN_ONCE flags |= libev.EVRUN_ONCE
self.keyboard_interrupt_allowed = False
libev.ev_run(self._ptr, flags) libev.ev_run(self._ptr, flags)
self.keyboard_interrupt_allowed = True
def reinit(self): def reinit(self):
libev.ev_loop_fork(self._ptr) libev.ev_loop_fork(self._ptr)
......
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
Event-loop hub. Event-loop hub.
""" """
from __future__ import absolute_import from __future__ import absolute_import
import sys from functools import partial as _functools_partial
import os import os
import sys
import traceback import traceback
from greenlet import greenlet, getcurrent, GreenletExit from greenlet import greenlet, getcurrent, GreenletExit
...@@ -112,14 +113,20 @@ class ConcurrentObjectUseError(AssertionError): ...@@ -112,14 +113,20 @@ class ConcurrentObjectUseError(AssertionError):
pass pass
def spawn_raw(function, *args): def spawn_raw(function, *args, **kwargs):
""" """
Create a new :class:`greenlet.greenlet` object and schedule it to run ``function(*args, **kwargs)``. Create a new :class:`greenlet.greenlet` object and schedule it to
run ``function(*args, **kwargs)``.
This returns a raw :class:`~greenlet.greenlet` which does not have all the useful
methods that :class:`gevent.Greenlet` has. Typically, applications
should prefer :func:`~gevent.spawn`, but this method may
occasionally be useful as an optimization if there are many
greenlets involved.
This returns a raw greenlet which does not have all the useful methods that .. versionchanged:: 1.1rc2
:class:`gevent.Greenlet` has. Typically, applications should prefer :func:`gevent.spawn`, Accept keyword arguments for ``function`` as previously (incorrectly)
but this method may occasionally be useful as an optimization if there are many greenlets documented. Note that this may incur an additional expense.
involved.
.. versionchanged:: 1.1a3 .. versionchanged:: 1.1a3
Verify that ``function`` is callable, raising a TypeError if not. Previously, Verify that ``function`` is callable, raising a TypeError if not. Previously,
...@@ -128,6 +135,15 @@ def spawn_raw(function, *args): ...@@ -128,6 +135,15 @@ def spawn_raw(function, *args):
if not callable(function): if not callable(function):
raise TypeError("function must be callable") raise TypeError("function must be callable")
hub = get_hub() hub = get_hub()
# The callback class object that we use to run this doesn't
# accept kwargs (and those objects are heavily used, as well as being
# implemented twice in core.ppyx and corecffi.py) so do it with a partial
if kwargs:
function = _functools_partial(function, *args, **kwargs)
g = greenlet(function, hub)
hub.loop.run_callback(g.switch)
else:
g = greenlet(function, hub) g = greenlet(function, hub)
hub.loop.run_callback(g.switch, *args) hub.loop.run_callback(g.switch, *args)
return g return g
......
...@@ -485,6 +485,17 @@ class TestBasic(greentest.TestCase): ...@@ -485,6 +485,17 @@ class TestBasic(greentest.TestCase):
# Passing both, but not implemented # Passing both, but not implemented
self.assertRaises(TypeError, gevent.spawn_later, 1, 1) self.assertRaises(TypeError, gevent.spawn_later, 1, 1)
def test_spawn_raw_kwargs(self):
value = []
def f(*args, **kwargs):
value.append(args)
value.append(kwargs)
g = gevent.spawn_raw(f, 1, name='value')
gevent.sleep(0.01)
self.assertEqual(value[0], (1,))
self.assertEqual(value[1], {'name': 'value'})
def test_simple_exit(self): def test_simple_exit(self):
link_test = [] link_test = []
......
...@@ -85,7 +85,7 @@ for var in "$@"; do ...@@ -85,7 +85,7 @@ for var in "$@"; do
install 2.6.9 python2.6 install 2.6.9 python2.6
;; ;;
2.7) 2.7)
install 2.7.9 python2.7 install 2.7.11 python2.7
;; ;;
3.2) 3.2)
install 3.2.6 python3.2 install 3.2.6 python3.2
...@@ -97,7 +97,7 @@ for var in "$@"; do ...@@ -97,7 +97,7 @@ for var in "$@"; do
install 3.4.3 python3.4 install 3.4.3 python3.4
;; ;;
3.5) 3.5)
install 3.5.0 python3.5 install 3.5.1 python3.5
;; ;;
pypy) pypy)
install pypy-4.0.1 pypy install pypy-4.0.1 pypy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment