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