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 @@
SIGCHLD signal at the process level (although this may allow race
conditions with libev child watchers). Reported in :issue:`696` by
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)
=====================
......
......@@ -518,9 +518,8 @@ class loop(object):
if once:
flags |= libev.EVRUN_ONCE
self.keyboard_interrupt_allowed = False
libev.ev_run(self._ptr, flags)
self.keyboard_interrupt_allowed = True
def reinit(self):
libev.ev_loop_fork(self._ptr)
......
......@@ -3,8 +3,9 @@
Event-loop hub.
"""
from __future__ import absolute_import
import sys
from functools import partial as _functools_partial
import os
import sys
import traceback
from greenlet import greenlet, getcurrent, GreenletExit
......@@ -112,14 +113,20 @@ class ConcurrentObjectUseError(AssertionError):
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
: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.
.. versionchanged:: 1.1rc2
Accept keyword arguments for ``function`` as previously (incorrectly)
documented. Note that this may incur an additional expense.
.. versionchanged:: 1.1a3
Verify that ``function`` is callable, raising a TypeError if not. Previously,
......@@ -128,8 +135,17 @@ def spawn_raw(function, *args):
if not callable(function):
raise TypeError("function must be callable")
hub = get_hub()
g = greenlet(function, hub)
hub.loop.run_callback(g.switch, *args)
# 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)
hub.loop.run_callback(g.switch, *args)
return g
......
......@@ -485,6 +485,17 @@ class TestBasic(greentest.TestCase):
# Passing both, but not implemented
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):
link_test = []
......
......@@ -85,7 +85,7 @@ for var in "$@"; do
install 2.6.9 python2.6
;;
2.7)
install 2.7.9 python2.7
install 2.7.11 python2.7
;;
3.2)
install 3.2.6 python3.2
......@@ -97,7 +97,7 @@ for var in "$@"; do
install 3.4.3 python3.4
;;
3.5)
install 3.5.0 python3.5
install 3.5.1 python3.5
;;
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