Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_asyncio_Future___init____doc__, |
| 6 | "Future(*, loop=None)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "This class is *almost* compatible with concurrent.futures.Future.\n" |
| 10 | "\n" |
| 11 | " Differences:\n" |
| 12 | "\n" |
| 13 | " - result() and exception() do not take a timeout argument and\n" |
| 14 | " raise an exception when the future isn\'t done yet.\n" |
| 15 | "\n" |
| 16 | " - Callbacks registered with add_done_callback() are always called\n" |
| 17 | " via the event loop\'s call_soon_threadsafe().\n" |
| 18 | "\n" |
| 19 | " - This class is not compatible with the wait() and as_completed()\n" |
| 20 | " methods in the concurrent.futures package."); |
| 21 | |
| 22 | static int |
| 23 | _asyncio_Future___init___impl(FutureObj *self, PyObject *loop); |
| 24 | |
| 25 | static int |
| 26 | _asyncio_Future___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 27 | { |
| 28 | int return_value = -1; |
| 29 | static const char * const _keywords[] = {"loop", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 30 | static _PyArg_Parser _parser = {NULL, _keywords, "Future", 0}; |
| 31 | PyObject *argsbuf[1]; |
| 32 | PyObject * const *fastargs; |
| 33 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 34 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
Serhiy Storchaka | bca4939 | 2017-09-03 08:10:14 +0300 | [diff] [blame] | 35 | PyObject *loop = Py_None; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 36 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 37 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 0, 0, argsbuf); |
| 38 | if (!fastargs) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 39 | goto exit; |
| 40 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 41 | if (!noptargs) { |
| 42 | goto skip_optional_kwonly; |
| 43 | } |
| 44 | loop = fastargs[0]; |
| 45 | skip_optional_kwonly: |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 46 | return_value = _asyncio_Future___init___impl((FutureObj *)self, loop); |
| 47 | |
| 48 | exit: |
| 49 | return return_value; |
| 50 | } |
| 51 | |
| 52 | PyDoc_STRVAR(_asyncio_Future_result__doc__, |
| 53 | "result($self, /)\n" |
| 54 | "--\n" |
| 55 | "\n" |
| 56 | "Return the result this future represents.\n" |
| 57 | "\n" |
| 58 | "If the future has been cancelled, raises CancelledError. If the\n" |
| 59 | "future\'s result isn\'t yet available, raises InvalidStateError. If\n" |
| 60 | "the future is done and has an exception set, this exception is raised."); |
| 61 | |
| 62 | #define _ASYNCIO_FUTURE_RESULT_METHODDEF \ |
| 63 | {"result", (PyCFunction)_asyncio_Future_result, METH_NOARGS, _asyncio_Future_result__doc__}, |
| 64 | |
| 65 | static PyObject * |
| 66 | _asyncio_Future_result_impl(FutureObj *self); |
| 67 | |
| 68 | static PyObject * |
| 69 | _asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 70 | { |
| 71 | return _asyncio_Future_result_impl(self); |
| 72 | } |
| 73 | |
| 74 | PyDoc_STRVAR(_asyncio_Future_exception__doc__, |
| 75 | "exception($self, /)\n" |
| 76 | "--\n" |
| 77 | "\n" |
| 78 | "Return the exception that was set on this future.\n" |
| 79 | "\n" |
| 80 | "The exception (or None if no exception was set) is returned only if\n" |
| 81 | "the future is done. If the future has been cancelled, raises\n" |
| 82 | "CancelledError. If the future isn\'t done yet, raises\n" |
| 83 | "InvalidStateError."); |
| 84 | |
| 85 | #define _ASYNCIO_FUTURE_EXCEPTION_METHODDEF \ |
| 86 | {"exception", (PyCFunction)_asyncio_Future_exception, METH_NOARGS, _asyncio_Future_exception__doc__}, |
| 87 | |
| 88 | static PyObject * |
| 89 | _asyncio_Future_exception_impl(FutureObj *self); |
| 90 | |
| 91 | static PyObject * |
| 92 | _asyncio_Future_exception(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 93 | { |
| 94 | return _asyncio_Future_exception_impl(self); |
| 95 | } |
| 96 | |
| 97 | PyDoc_STRVAR(_asyncio_Future_set_result__doc__, |
Yury Selivanov | 0cf16f9 | 2017-12-25 10:48:15 -0500 | [diff] [blame] | 98 | "set_result($self, result, /)\n" |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 99 | "--\n" |
| 100 | "\n" |
| 101 | "Mark the future done and set its result.\n" |
| 102 | "\n" |
| 103 | "If the future is already done when this method is called, raises\n" |
| 104 | "InvalidStateError."); |
| 105 | |
| 106 | #define _ASYNCIO_FUTURE_SET_RESULT_METHODDEF \ |
| 107 | {"set_result", (PyCFunction)_asyncio_Future_set_result, METH_O, _asyncio_Future_set_result__doc__}, |
| 108 | |
| 109 | PyDoc_STRVAR(_asyncio_Future_set_exception__doc__, |
| 110 | "set_exception($self, exception, /)\n" |
| 111 | "--\n" |
| 112 | "\n" |
| 113 | "Mark the future done and set an exception.\n" |
| 114 | "\n" |
| 115 | "If the future is already done when this method is called, raises\n" |
| 116 | "InvalidStateError."); |
| 117 | |
| 118 | #define _ASYNCIO_FUTURE_SET_EXCEPTION_METHODDEF \ |
| 119 | {"set_exception", (PyCFunction)_asyncio_Future_set_exception, METH_O, _asyncio_Future_set_exception__doc__}, |
| 120 | |
| 121 | PyDoc_STRVAR(_asyncio_Future_add_done_callback__doc__, |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 122 | "add_done_callback($self, fn, /, *, context=None)\n" |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 123 | "--\n" |
| 124 | "\n" |
| 125 | "Add a callback to be run when the future becomes done.\n" |
| 126 | "\n" |
| 127 | "The callback is called with a single argument - the future object. If\n" |
| 128 | "the future is already done when this is called, the callback is\n" |
| 129 | "scheduled with call_soon."); |
| 130 | |
| 131 | #define _ASYNCIO_FUTURE_ADD_DONE_CALLBACK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 132 | {"add_done_callback", (PyCFunction)(void(*)(void))_asyncio_Future_add_done_callback, METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_add_done_callback__doc__}, |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 133 | |
| 134 | static PyObject * |
| 135 | _asyncio_Future_add_done_callback_impl(FutureObj *self, PyObject *fn, |
| 136 | PyObject *context); |
| 137 | |
| 138 | static PyObject * |
| 139 | _asyncio_Future_add_done_callback(FutureObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 140 | { |
| 141 | PyObject *return_value = NULL; |
| 142 | static const char * const _keywords[] = {"", "context", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 143 | static _PyArg_Parser _parser = {NULL, _keywords, "add_done_callback", 0}; |
| 144 | PyObject *argsbuf[2]; |
| 145 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 146 | PyObject *fn; |
| 147 | PyObject *context = NULL; |
| 148 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 149 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 150 | if (!args) { |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 151 | goto exit; |
| 152 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 153 | fn = args[0]; |
| 154 | if (!noptargs) { |
| 155 | goto skip_optional_kwonly; |
| 156 | } |
| 157 | context = args[1]; |
| 158 | skip_optional_kwonly: |
Yury Selivanov | f23746a | 2018-01-22 19:11:18 -0500 | [diff] [blame] | 159 | return_value = _asyncio_Future_add_done_callback_impl(self, fn, context); |
| 160 | |
| 161 | exit: |
| 162 | return return_value; |
| 163 | } |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 164 | |
| 165 | PyDoc_STRVAR(_asyncio_Future_remove_done_callback__doc__, |
| 166 | "remove_done_callback($self, fn, /)\n" |
| 167 | "--\n" |
| 168 | "\n" |
| 169 | "Remove all instances of a callback from the \"call when done\" list.\n" |
| 170 | "\n" |
| 171 | "Returns the number of callbacks removed."); |
| 172 | |
| 173 | #define _ASYNCIO_FUTURE_REMOVE_DONE_CALLBACK_METHODDEF \ |
| 174 | {"remove_done_callback", (PyCFunction)_asyncio_Future_remove_done_callback, METH_O, _asyncio_Future_remove_done_callback__doc__}, |
| 175 | |
| 176 | PyDoc_STRVAR(_asyncio_Future_cancel__doc__, |
| 177 | "cancel($self, /)\n" |
| 178 | "--\n" |
| 179 | "\n" |
| 180 | "Cancel the future and schedule callbacks.\n" |
| 181 | "\n" |
| 182 | "If the future is already done or cancelled, return False. Otherwise,\n" |
| 183 | "change the future\'s state to cancelled, schedule the callbacks and\n" |
| 184 | "return True."); |
| 185 | |
| 186 | #define _ASYNCIO_FUTURE_CANCEL_METHODDEF \ |
| 187 | {"cancel", (PyCFunction)_asyncio_Future_cancel, METH_NOARGS, _asyncio_Future_cancel__doc__}, |
| 188 | |
| 189 | static PyObject * |
| 190 | _asyncio_Future_cancel_impl(FutureObj *self); |
| 191 | |
| 192 | static PyObject * |
| 193 | _asyncio_Future_cancel(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 194 | { |
| 195 | return _asyncio_Future_cancel_impl(self); |
| 196 | } |
| 197 | |
| 198 | PyDoc_STRVAR(_asyncio_Future_cancelled__doc__, |
| 199 | "cancelled($self, /)\n" |
| 200 | "--\n" |
| 201 | "\n" |
| 202 | "Return True if the future was cancelled."); |
| 203 | |
| 204 | #define _ASYNCIO_FUTURE_CANCELLED_METHODDEF \ |
| 205 | {"cancelled", (PyCFunction)_asyncio_Future_cancelled, METH_NOARGS, _asyncio_Future_cancelled__doc__}, |
| 206 | |
| 207 | static PyObject * |
| 208 | _asyncio_Future_cancelled_impl(FutureObj *self); |
| 209 | |
| 210 | static PyObject * |
| 211 | _asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 212 | { |
| 213 | return _asyncio_Future_cancelled_impl(self); |
| 214 | } |
| 215 | |
| 216 | PyDoc_STRVAR(_asyncio_Future_done__doc__, |
| 217 | "done($self, /)\n" |
| 218 | "--\n" |
| 219 | "\n" |
| 220 | "Return True if the future is done.\n" |
| 221 | "\n" |
| 222 | "Done means either that a result / exception are available, or that the\n" |
| 223 | "future was cancelled."); |
| 224 | |
| 225 | #define _ASYNCIO_FUTURE_DONE_METHODDEF \ |
| 226 | {"done", (PyCFunction)_asyncio_Future_done, METH_NOARGS, _asyncio_Future_done__doc__}, |
| 227 | |
| 228 | static PyObject * |
| 229 | _asyncio_Future_done_impl(FutureObj *self); |
| 230 | |
| 231 | static PyObject * |
| 232 | _asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 233 | { |
| 234 | return _asyncio_Future_done_impl(self); |
| 235 | } |
| 236 | |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 237 | PyDoc_STRVAR(_asyncio_Future_get_loop__doc__, |
| 238 | "get_loop($self, /)\n" |
| 239 | "--\n" |
| 240 | "\n" |
| 241 | "Return the event loop the Future is bound to."); |
| 242 | |
| 243 | #define _ASYNCIO_FUTURE_GET_LOOP_METHODDEF \ |
| 244 | {"get_loop", (PyCFunction)_asyncio_Future_get_loop, METH_NOARGS, _asyncio_Future_get_loop__doc__}, |
| 245 | |
| 246 | static PyObject * |
| 247 | _asyncio_Future_get_loop_impl(FutureObj *self); |
| 248 | |
| 249 | static PyObject * |
| 250 | _asyncio_Future_get_loop(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 251 | { |
| 252 | return _asyncio_Future_get_loop_impl(self); |
| 253 | } |
| 254 | |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 255 | PyDoc_STRVAR(_asyncio_Future__repr_info__doc__, |
| 256 | "_repr_info($self, /)\n" |
| 257 | "--\n" |
| 258 | "\n"); |
| 259 | |
| 260 | #define _ASYNCIO_FUTURE__REPR_INFO_METHODDEF \ |
| 261 | {"_repr_info", (PyCFunction)_asyncio_Future__repr_info, METH_NOARGS, _asyncio_Future__repr_info__doc__}, |
| 262 | |
| 263 | static PyObject * |
| 264 | _asyncio_Future__repr_info_impl(FutureObj *self); |
| 265 | |
| 266 | static PyObject * |
| 267 | _asyncio_Future__repr_info(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 268 | { |
| 269 | return _asyncio_Future__repr_info_impl(self); |
| 270 | } |
| 271 | |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 272 | PyDoc_STRVAR(_asyncio_Task___init____doc__, |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 273 | "Task(coro, *, loop=None, name=None)\n" |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 274 | "--\n" |
| 275 | "\n" |
| 276 | "A coroutine wrapped in a Future."); |
| 277 | |
| 278 | static int |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 279 | _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, |
| 280 | PyObject *name); |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 281 | |
| 282 | static int |
| 283 | _asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 284 | { |
| 285 | int return_value = -1; |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 286 | static const char * const _keywords[] = {"coro", "loop", "name", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 287 | static _PyArg_Parser _parser = {NULL, _keywords, "Task", 0}; |
| 288 | PyObject *argsbuf[3]; |
| 289 | PyObject * const *fastargs; |
| 290 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 291 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 292 | PyObject *coro; |
Serhiy Storchaka | bca4939 | 2017-09-03 08:10:14 +0300 | [diff] [blame] | 293 | PyObject *loop = Py_None; |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 294 | PyObject *name = Py_None; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 295 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 296 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); |
| 297 | if (!fastargs) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 298 | goto exit; |
| 299 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 300 | coro = fastargs[0]; |
| 301 | if (!noptargs) { |
| 302 | goto skip_optional_kwonly; |
| 303 | } |
| 304 | if (fastargs[1]) { |
| 305 | loop = fastargs[1]; |
| 306 | if (!--noptargs) { |
| 307 | goto skip_optional_kwonly; |
| 308 | } |
| 309 | } |
| 310 | name = fastargs[2]; |
| 311 | skip_optional_kwonly: |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 312 | return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop, name); |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 313 | |
| 314 | exit: |
| 315 | return return_value; |
| 316 | } |
| 317 | |
| 318 | PyDoc_STRVAR(_asyncio_Task_current_task__doc__, |
| 319 | "current_task($type, /, loop=None)\n" |
| 320 | "--\n" |
| 321 | "\n" |
| 322 | "Return the currently running task in an event loop or None.\n" |
| 323 | "\n" |
| 324 | "By default the current task for the current event loop is returned.\n" |
| 325 | "\n" |
| 326 | "None is returned when called not in the context of a Task."); |
| 327 | |
| 328 | #define _ASYNCIO_TASK_CURRENT_TASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 329 | {"current_task", (PyCFunction)(void(*)(void))_asyncio_Task_current_task, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_current_task__doc__}, |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 330 | |
| 331 | static PyObject * |
| 332 | _asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop); |
| 333 | |
| 334 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 335 | _asyncio_Task_current_task(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 336 | { |
| 337 | PyObject *return_value = NULL; |
| 338 | static const char * const _keywords[] = {"loop", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 339 | static _PyArg_Parser _parser = {NULL, _keywords, "current_task", 0}; |
| 340 | PyObject *argsbuf[1]; |
| 341 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Yury Selivanov | 8d26aa9 | 2017-03-02 22:16:33 -0500 | [diff] [blame] | 342 | PyObject *loop = Py_None; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 343 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 344 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 345 | if (!args) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 346 | goto exit; |
| 347 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 348 | if (!noptargs) { |
| 349 | goto skip_optional_pos; |
| 350 | } |
| 351 | loop = args[0]; |
| 352 | skip_optional_pos: |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 353 | return_value = _asyncio_Task_current_task_impl(type, loop); |
| 354 | |
| 355 | exit: |
| 356 | return return_value; |
| 357 | } |
| 358 | |
| 359 | PyDoc_STRVAR(_asyncio_Task_all_tasks__doc__, |
| 360 | "all_tasks($type, /, loop=None)\n" |
| 361 | "--\n" |
| 362 | "\n" |
| 363 | "Return a set of all tasks for an event loop.\n" |
| 364 | "\n" |
| 365 | "By default all tasks for the current event loop are returned."); |
| 366 | |
| 367 | #define _ASYNCIO_TASK_ALL_TASKS_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 368 | {"all_tasks", (PyCFunction)(void(*)(void))_asyncio_Task_all_tasks, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_all_tasks__doc__}, |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 369 | |
| 370 | static PyObject * |
| 371 | _asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop); |
| 372 | |
| 373 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 374 | _asyncio_Task_all_tasks(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 375 | { |
| 376 | PyObject *return_value = NULL; |
| 377 | static const char * const _keywords[] = {"loop", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 378 | static _PyArg_Parser _parser = {NULL, _keywords, "all_tasks", 0}; |
| 379 | PyObject *argsbuf[1]; |
| 380 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Yury Selivanov | 8d26aa9 | 2017-03-02 22:16:33 -0500 | [diff] [blame] | 381 | PyObject *loop = Py_None; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 382 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 383 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 384 | if (!args) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 385 | goto exit; |
| 386 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 387 | if (!noptargs) { |
| 388 | goto skip_optional_pos; |
| 389 | } |
| 390 | loop = args[0]; |
| 391 | skip_optional_pos: |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 392 | return_value = _asyncio_Task_all_tasks_impl(type, loop); |
| 393 | |
| 394 | exit: |
| 395 | return return_value; |
| 396 | } |
| 397 | |
| 398 | PyDoc_STRVAR(_asyncio_Task__repr_info__doc__, |
| 399 | "_repr_info($self, /)\n" |
| 400 | "--\n" |
| 401 | "\n"); |
| 402 | |
| 403 | #define _ASYNCIO_TASK__REPR_INFO_METHODDEF \ |
| 404 | {"_repr_info", (PyCFunction)_asyncio_Task__repr_info, METH_NOARGS, _asyncio_Task__repr_info__doc__}, |
| 405 | |
| 406 | static PyObject * |
| 407 | _asyncio_Task__repr_info_impl(TaskObj *self); |
| 408 | |
| 409 | static PyObject * |
| 410 | _asyncio_Task__repr_info(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 411 | { |
| 412 | return _asyncio_Task__repr_info_impl(self); |
| 413 | } |
| 414 | |
| 415 | PyDoc_STRVAR(_asyncio_Task_cancel__doc__, |
| 416 | "cancel($self, /)\n" |
| 417 | "--\n" |
| 418 | "\n" |
| 419 | "Request that this task cancel itself.\n" |
| 420 | "\n" |
| 421 | "This arranges for a CancelledError to be thrown into the\n" |
| 422 | "wrapped coroutine on the next cycle through the event loop.\n" |
| 423 | "The coroutine then has a chance to clean up or even deny\n" |
| 424 | "the request using try/except/finally.\n" |
| 425 | "\n" |
| 426 | "Unlike Future.cancel, this does not guarantee that the\n" |
| 427 | "task will be cancelled: the exception might be caught and\n" |
| 428 | "acted upon, delaying cancellation of the task or preventing\n" |
| 429 | "cancellation completely. The task may also return a value or\n" |
| 430 | "raise a different exception.\n" |
| 431 | "\n" |
| 432 | "Immediately after this method is called, Task.cancelled() will\n" |
| 433 | "not return True (unless the task was already cancelled). A\n" |
| 434 | "task will be marked as cancelled when the wrapped coroutine\n" |
| 435 | "terminates with a CancelledError exception (even if cancel()\n" |
| 436 | "was not called)."); |
| 437 | |
| 438 | #define _ASYNCIO_TASK_CANCEL_METHODDEF \ |
| 439 | {"cancel", (PyCFunction)_asyncio_Task_cancel, METH_NOARGS, _asyncio_Task_cancel__doc__}, |
| 440 | |
| 441 | static PyObject * |
| 442 | _asyncio_Task_cancel_impl(TaskObj *self); |
| 443 | |
| 444 | static PyObject * |
| 445 | _asyncio_Task_cancel(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 446 | { |
| 447 | return _asyncio_Task_cancel_impl(self); |
| 448 | } |
| 449 | |
| 450 | PyDoc_STRVAR(_asyncio_Task_get_stack__doc__, |
| 451 | "get_stack($self, /, *, limit=None)\n" |
| 452 | "--\n" |
| 453 | "\n" |
| 454 | "Return the list of stack frames for this task\'s coroutine.\n" |
| 455 | "\n" |
| 456 | "If the coroutine is not done, this returns the stack where it is\n" |
| 457 | "suspended. If the coroutine has completed successfully or was\n" |
| 458 | "cancelled, this returns an empty list. If the coroutine was\n" |
| 459 | "terminated by an exception, this returns the list of traceback\n" |
| 460 | "frames.\n" |
| 461 | "\n" |
| 462 | "The frames are always ordered from oldest to newest.\n" |
| 463 | "\n" |
| 464 | "The optional limit gives the maximum number of frames to\n" |
| 465 | "return; by default all available frames are returned. Its\n" |
| 466 | "meaning differs depending on whether a stack or a traceback is\n" |
| 467 | "returned: the newest frames of a stack are returned, but the\n" |
| 468 | "oldest frames of a traceback are returned. (This matches the\n" |
| 469 | "behavior of the traceback module.)\n" |
| 470 | "\n" |
| 471 | "For reasons beyond our control, only one stack frame is\n" |
| 472 | "returned for a suspended coroutine."); |
| 473 | |
| 474 | #define _ASYNCIO_TASK_GET_STACK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 475 | {"get_stack", (PyCFunction)(void(*)(void))_asyncio_Task_get_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__}, |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 476 | |
| 477 | static PyObject * |
| 478 | _asyncio_Task_get_stack_impl(TaskObj *self, PyObject *limit); |
| 479 | |
| 480 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 481 | _asyncio_Task_get_stack(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 482 | { |
| 483 | PyObject *return_value = NULL; |
| 484 | static const char * const _keywords[] = {"limit", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 485 | static _PyArg_Parser _parser = {NULL, _keywords, "get_stack", 0}; |
| 486 | PyObject *argsbuf[1]; |
| 487 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 488 | PyObject *limit = Py_None; |
| 489 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 490 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 491 | if (!args) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 492 | goto exit; |
| 493 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 494 | if (!noptargs) { |
| 495 | goto skip_optional_kwonly; |
| 496 | } |
| 497 | limit = args[0]; |
| 498 | skip_optional_kwonly: |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 499 | return_value = _asyncio_Task_get_stack_impl(self, limit); |
| 500 | |
| 501 | exit: |
| 502 | return return_value; |
| 503 | } |
| 504 | |
| 505 | PyDoc_STRVAR(_asyncio_Task_print_stack__doc__, |
| 506 | "print_stack($self, /, *, limit=None, file=None)\n" |
| 507 | "--\n" |
| 508 | "\n" |
| 509 | "Print the stack or traceback for this task\'s coroutine.\n" |
| 510 | "\n" |
| 511 | "This produces output similar to that of the traceback module,\n" |
| 512 | "for the frames retrieved by get_stack(). The limit argument\n" |
| 513 | "is passed to get_stack(). The file argument is an I/O stream\n" |
| 514 | "to which the output is written; by default output is written\n" |
| 515 | "to sys.stderr."); |
| 516 | |
| 517 | #define _ASYNCIO_TASK_PRINT_STACK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 518 | {"print_stack", (PyCFunction)(void(*)(void))_asyncio_Task_print_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__}, |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 519 | |
| 520 | static PyObject * |
| 521 | _asyncio_Task_print_stack_impl(TaskObj *self, PyObject *limit, |
| 522 | PyObject *file); |
| 523 | |
| 524 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 525 | _asyncio_Task_print_stack(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 526 | { |
| 527 | PyObject *return_value = NULL; |
| 528 | static const char * const _keywords[] = {"limit", "file", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 529 | static _PyArg_Parser _parser = {NULL, _keywords, "print_stack", 0}; |
| 530 | PyObject *argsbuf[2]; |
| 531 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 532 | PyObject *limit = Py_None; |
| 533 | PyObject *file = Py_None; |
| 534 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 535 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 536 | if (!args) { |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 537 | goto exit; |
| 538 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 539 | if (!noptargs) { |
| 540 | goto skip_optional_kwonly; |
| 541 | } |
| 542 | if (args[0]) { |
| 543 | limit = args[0]; |
| 544 | if (!--noptargs) { |
| 545 | goto skip_optional_kwonly; |
| 546 | } |
| 547 | } |
| 548 | file = args[1]; |
| 549 | skip_optional_kwonly: |
Yury Selivanov | a0c1ba6 | 2016-10-28 12:52:37 -0400 | [diff] [blame] | 550 | return_value = _asyncio_Task_print_stack_impl(self, limit, file); |
| 551 | |
| 552 | exit: |
| 553 | return return_value; |
| 554 | } |
| 555 | |
Yury Selivanov | 0cf16f9 | 2017-12-25 10:48:15 -0500 | [diff] [blame] | 556 | PyDoc_STRVAR(_asyncio_Task_set_result__doc__, |
| 557 | "set_result($self, result, /)\n" |
| 558 | "--\n" |
| 559 | "\n"); |
| 560 | |
| 561 | #define _ASYNCIO_TASK_SET_RESULT_METHODDEF \ |
| 562 | {"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__}, |
| 563 | |
| 564 | PyDoc_STRVAR(_asyncio_Task_set_exception__doc__, |
| 565 | "set_exception($self, exception, /)\n" |
| 566 | "--\n" |
| 567 | "\n"); |
| 568 | |
| 569 | #define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF \ |
| 570 | {"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__}, |
| 571 | |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 572 | PyDoc_STRVAR(_asyncio_Task_get_name__doc__, |
| 573 | "get_name($self, /)\n" |
| 574 | "--\n" |
| 575 | "\n"); |
| 576 | |
| 577 | #define _ASYNCIO_TASK_GET_NAME_METHODDEF \ |
| 578 | {"get_name", (PyCFunction)_asyncio_Task_get_name, METH_NOARGS, _asyncio_Task_get_name__doc__}, |
| 579 | |
| 580 | static PyObject * |
| 581 | _asyncio_Task_get_name_impl(TaskObj *self); |
| 582 | |
| 583 | static PyObject * |
| 584 | _asyncio_Task_get_name(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 585 | { |
| 586 | return _asyncio_Task_get_name_impl(self); |
| 587 | } |
| 588 | |
| 589 | PyDoc_STRVAR(_asyncio_Task_set_name__doc__, |
| 590 | "set_name($self, value, /)\n" |
| 591 | "--\n" |
| 592 | "\n"); |
| 593 | |
| 594 | #define _ASYNCIO_TASK_SET_NAME_METHODDEF \ |
| 595 | {"set_name", (PyCFunction)_asyncio_Task_set_name, METH_O, _asyncio_Task_set_name__doc__}, |
| 596 | |
Yury Selivanov | a70232f | 2017-12-13 14:49:42 -0500 | [diff] [blame] | 597 | PyDoc_STRVAR(_asyncio__get_running_loop__doc__, |
| 598 | "_get_running_loop($module, /)\n" |
| 599 | "--\n" |
| 600 | "\n" |
| 601 | "Return the running event loop or None.\n" |
| 602 | "\n" |
| 603 | "This is a low-level function intended to be used by event loops.\n" |
| 604 | "This function is thread-specific."); |
| 605 | |
| 606 | #define _ASYNCIO__GET_RUNNING_LOOP_METHODDEF \ |
| 607 | {"_get_running_loop", (PyCFunction)_asyncio__get_running_loop, METH_NOARGS, _asyncio__get_running_loop__doc__}, |
| 608 | |
| 609 | static PyObject * |
| 610 | _asyncio__get_running_loop_impl(PyObject *module); |
| 611 | |
| 612 | static PyObject * |
| 613 | _asyncio__get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 614 | { |
| 615 | return _asyncio__get_running_loop_impl(module); |
| 616 | } |
| 617 | |
| 618 | PyDoc_STRVAR(_asyncio__set_running_loop__doc__, |
| 619 | "_set_running_loop($module, loop, /)\n" |
| 620 | "--\n" |
| 621 | "\n" |
| 622 | "Set the running event loop.\n" |
| 623 | "\n" |
| 624 | "This is a low-level function intended to be used by event loops.\n" |
| 625 | "This function is thread-specific."); |
| 626 | |
| 627 | #define _ASYNCIO__SET_RUNNING_LOOP_METHODDEF \ |
| 628 | {"_set_running_loop", (PyCFunction)_asyncio__set_running_loop, METH_O, _asyncio__set_running_loop__doc__}, |
| 629 | |
| 630 | PyDoc_STRVAR(_asyncio_get_event_loop__doc__, |
| 631 | "get_event_loop($module, /)\n" |
| 632 | "--\n" |
| 633 | "\n" |
| 634 | "Return an asyncio event loop.\n" |
| 635 | "\n" |
| 636 | "When called from a coroutine or a callback (e.g. scheduled with\n" |
| 637 | "call_soon or similar API), this function will always return the\n" |
| 638 | "running event loop.\n" |
| 639 | "\n" |
| 640 | "If there is no running event loop set, the function will return\n" |
| 641 | "the result of `get_event_loop_policy().get_event_loop()` call."); |
| 642 | |
| 643 | #define _ASYNCIO_GET_EVENT_LOOP_METHODDEF \ |
| 644 | {"get_event_loop", (PyCFunction)_asyncio_get_event_loop, METH_NOARGS, _asyncio_get_event_loop__doc__}, |
| 645 | |
| 646 | static PyObject * |
| 647 | _asyncio_get_event_loop_impl(PyObject *module); |
| 648 | |
| 649 | static PyObject * |
| 650 | _asyncio_get_event_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 651 | { |
| 652 | return _asyncio_get_event_loop_impl(module); |
| 653 | } |
| 654 | |
| 655 | PyDoc_STRVAR(_asyncio_get_running_loop__doc__, |
| 656 | "get_running_loop($module, /)\n" |
| 657 | "--\n" |
| 658 | "\n" |
| 659 | "Return the running event loop. Raise a RuntimeError if there is none.\n" |
| 660 | "\n" |
| 661 | "This function is thread-specific."); |
| 662 | |
| 663 | #define _ASYNCIO_GET_RUNNING_LOOP_METHODDEF \ |
| 664 | {"get_running_loop", (PyCFunction)_asyncio_get_running_loop, METH_NOARGS, _asyncio_get_running_loop__doc__}, |
| 665 | |
| 666 | static PyObject * |
| 667 | _asyncio_get_running_loop_impl(PyObject *module); |
| 668 | |
| 669 | static PyObject * |
| 670 | _asyncio_get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 671 | { |
| 672 | return _asyncio_get_running_loop_impl(module); |
| 673 | } |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 674 | |
| 675 | PyDoc_STRVAR(_asyncio__register_task__doc__, |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 676 | "_register_task($module, /, task)\n" |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 677 | "--\n" |
| 678 | "\n" |
| 679 | "Register a new task in asyncio as executed by loop.\n" |
| 680 | "\n" |
| 681 | "Returns None."); |
| 682 | |
| 683 | #define _ASYNCIO__REGISTER_TASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 684 | {"_register_task", (PyCFunction)(void(*)(void))_asyncio__register_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__register_task__doc__}, |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 685 | |
| 686 | static PyObject * |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 687 | _asyncio__register_task_impl(PyObject *module, PyObject *task); |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 688 | |
| 689 | static PyObject * |
| 690 | _asyncio__register_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 691 | { |
| 692 | PyObject *return_value = NULL; |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 693 | static const char * const _keywords[] = {"task", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 694 | static _PyArg_Parser _parser = {NULL, _keywords, "_register_task", 0}; |
| 695 | PyObject *argsbuf[1]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 696 | PyObject *task; |
| 697 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 698 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 699 | if (!args) { |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 700 | goto exit; |
| 701 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 702 | task = args[0]; |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 703 | return_value = _asyncio__register_task_impl(module, task); |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 704 | |
| 705 | exit: |
| 706 | return return_value; |
| 707 | } |
| 708 | |
| 709 | PyDoc_STRVAR(_asyncio__unregister_task__doc__, |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 710 | "_unregister_task($module, /, task)\n" |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 711 | "--\n" |
| 712 | "\n" |
| 713 | "Unregister a task.\n" |
| 714 | "\n" |
| 715 | "Returns None."); |
| 716 | |
| 717 | #define _ASYNCIO__UNREGISTER_TASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 718 | {"_unregister_task", (PyCFunction)(void(*)(void))_asyncio__unregister_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_task__doc__}, |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 719 | |
| 720 | static PyObject * |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 721 | _asyncio__unregister_task_impl(PyObject *module, PyObject *task); |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 722 | |
| 723 | static PyObject * |
| 724 | _asyncio__unregister_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 725 | { |
| 726 | PyObject *return_value = NULL; |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 727 | static const char * const _keywords[] = {"task", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 728 | static _PyArg_Parser _parser = {NULL, _keywords, "_unregister_task", 0}; |
| 729 | PyObject *argsbuf[1]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 730 | PyObject *task; |
| 731 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 732 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 733 | if (!args) { |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 734 | goto exit; |
| 735 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 736 | task = args[0]; |
Yury Selivanov | ca9b36c | 2017-12-23 15:04:15 -0500 | [diff] [blame] | 737 | return_value = _asyncio__unregister_task_impl(module, task); |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 738 | |
| 739 | exit: |
| 740 | return return_value; |
| 741 | } |
| 742 | |
| 743 | PyDoc_STRVAR(_asyncio__enter_task__doc__, |
| 744 | "_enter_task($module, /, loop, task)\n" |
| 745 | "--\n" |
| 746 | "\n" |
| 747 | "Enter into task execution or resume suspended task.\n" |
| 748 | "\n" |
| 749 | "Task belongs to loop.\n" |
| 750 | "\n" |
| 751 | "Returns None."); |
| 752 | |
| 753 | #define _ASYNCIO__ENTER_TASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 754 | {"_enter_task", (PyCFunction)(void(*)(void))_asyncio__enter_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__enter_task__doc__}, |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 755 | |
| 756 | static PyObject * |
| 757 | _asyncio__enter_task_impl(PyObject *module, PyObject *loop, PyObject *task); |
| 758 | |
| 759 | static PyObject * |
| 760 | _asyncio__enter_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 761 | { |
| 762 | PyObject *return_value = NULL; |
| 763 | static const char * const _keywords[] = {"loop", "task", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 764 | static _PyArg_Parser _parser = {NULL, _keywords, "_enter_task", 0}; |
| 765 | PyObject *argsbuf[2]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 766 | PyObject *loop; |
| 767 | PyObject *task; |
| 768 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 769 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 770 | if (!args) { |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 771 | goto exit; |
| 772 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 773 | loop = args[0]; |
| 774 | task = args[1]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 775 | return_value = _asyncio__enter_task_impl(module, loop, task); |
| 776 | |
| 777 | exit: |
| 778 | return return_value; |
| 779 | } |
| 780 | |
| 781 | PyDoc_STRVAR(_asyncio__leave_task__doc__, |
| 782 | "_leave_task($module, /, loop, task)\n" |
| 783 | "--\n" |
| 784 | "\n" |
| 785 | "Leave task execution or suspend a task.\n" |
| 786 | "\n" |
| 787 | "Task belongs to loop.\n" |
| 788 | "\n" |
| 789 | "Returns None."); |
| 790 | |
| 791 | #define _ASYNCIO__LEAVE_TASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 792 | {"_leave_task", (PyCFunction)(void(*)(void))_asyncio__leave_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__leave_task__doc__}, |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 793 | |
| 794 | static PyObject * |
| 795 | _asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task); |
| 796 | |
| 797 | static PyObject * |
| 798 | _asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 799 | { |
| 800 | PyObject *return_value = NULL; |
| 801 | static const char * const _keywords[] = {"loop", "task", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 802 | static _PyArg_Parser _parser = {NULL, _keywords, "_leave_task", 0}; |
| 803 | PyObject *argsbuf[2]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 804 | PyObject *loop; |
| 805 | PyObject *task; |
| 806 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 807 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 808 | if (!args) { |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 809 | goto exit; |
| 810 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 811 | loop = args[0]; |
| 812 | task = args[1]; |
Andrew Svetlov | 44d1a59 | 2017-12-16 21:58:38 +0200 | [diff] [blame] | 813 | return_value = _asyncio__leave_task_impl(module, loop, task); |
| 814 | |
| 815 | exit: |
| 816 | return return_value; |
| 817 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame^] | 818 | /*[clinic end generated code: output=e3b02d96da56e80c input=a9049054013a1b77]*/ |