Home | History | Annotate | Download | only in clinic
      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};
     31     PyObject *loop = NULL;
     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__,
     89 "set_result($self, res, /)\n"
     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__,
    113 "add_done_callback($self, fn, /)\n"
    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    \
    123     {"add_done_callback", (PyCFunction)_asyncio_Future_add_done_callback, METH_O, _asyncio_Future_add_done_callback__doc__},
    124 
    125 PyDoc_STRVAR(_asyncio_Future_remove_done_callback__doc__,
    126 "remove_done_callback($self, fn, /)\n"
    127 "--\n"
    128 "\n"
    129 "Remove all instances of a callback from the \"call when done\" list.\n"
    130 "\n"
    131 "Returns the number of callbacks removed.");
    132 
    133 #define _ASYNCIO_FUTURE_REMOVE_DONE_CALLBACK_METHODDEF    \
    134     {"remove_done_callback", (PyCFunction)_asyncio_Future_remove_done_callback, METH_O, _asyncio_Future_remove_done_callback__doc__},
    135 
    136 PyDoc_STRVAR(_asyncio_Future_cancel__doc__,
    137 "cancel($self, /)\n"
    138 "--\n"
    139 "\n"
    140 "Cancel the future and schedule callbacks.\n"
    141 "\n"
    142 "If the future is already done or cancelled, return False.  Otherwise,\n"
    143 "change the future\'s state to cancelled, schedule the callbacks and\n"
    144 "return True.");
    145 
    146 #define _ASYNCIO_FUTURE_CANCEL_METHODDEF    \
    147     {"cancel", (PyCFunction)_asyncio_Future_cancel, METH_NOARGS, _asyncio_Future_cancel__doc__},
    148 
    149 static PyObject *
    150 _asyncio_Future_cancel_impl(FutureObj *self);
    151 
    152 static PyObject *
    153 _asyncio_Future_cancel(FutureObj *self, PyObject *Py_UNUSED(ignored))
    154 {
    155     return _asyncio_Future_cancel_impl(self);
    156 }
    157 
    158 PyDoc_STRVAR(_asyncio_Future_cancelled__doc__,
    159 "cancelled($self, /)\n"
    160 "--\n"
    161 "\n"
    162 "Return True if the future was cancelled.");
    163 
    164 #define _ASYNCIO_FUTURE_CANCELLED_METHODDEF    \
    165     {"cancelled", (PyCFunction)_asyncio_Future_cancelled, METH_NOARGS, _asyncio_Future_cancelled__doc__},
    166 
    167 static PyObject *
    168 _asyncio_Future_cancelled_impl(FutureObj *self);
    169 
    170 static PyObject *
    171 _asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored))
    172 {
    173     return _asyncio_Future_cancelled_impl(self);
    174 }
    175 
    176 PyDoc_STRVAR(_asyncio_Future_done__doc__,
    177 "done($self, /)\n"
    178 "--\n"
    179 "\n"
    180 "Return True if the future is done.\n"
    181 "\n"
    182 "Done means either that a result / exception are available, or that the\n"
    183 "future was cancelled.");
    184 
    185 #define _ASYNCIO_FUTURE_DONE_METHODDEF    \
    186     {"done", (PyCFunction)_asyncio_Future_done, METH_NOARGS, _asyncio_Future_done__doc__},
    187 
    188 static PyObject *
    189 _asyncio_Future_done_impl(FutureObj *self);
    190 
    191 static PyObject *
    192 _asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored))
    193 {
    194     return _asyncio_Future_done_impl(self);
    195 }
    196 
    197 PyDoc_STRVAR(_asyncio_Future__repr_info__doc__,
    198 "_repr_info($self, /)\n"
    199 "--\n"
    200 "\n");
    201 
    202 #define _ASYNCIO_FUTURE__REPR_INFO_METHODDEF    \
    203     {"_repr_info", (PyCFunction)_asyncio_Future__repr_info, METH_NOARGS, _asyncio_Future__repr_info__doc__},
    204 
    205 static PyObject *
    206 _asyncio_Future__repr_info_impl(FutureObj *self);
    207 
    208 static PyObject *
    209 _asyncio_Future__repr_info(FutureObj *self, PyObject *Py_UNUSED(ignored))
    210 {
    211     return _asyncio_Future__repr_info_impl(self);
    212 }
    213 
    214 PyDoc_STRVAR(_asyncio_Future__schedule_callbacks__doc__,
    215 "_schedule_callbacks($self, /)\n"
    216 "--\n"
    217 "\n");
    218 
    219 #define _ASYNCIO_FUTURE__SCHEDULE_CALLBACKS_METHODDEF    \
    220     {"_schedule_callbacks", (PyCFunction)_asyncio_Future__schedule_callbacks, METH_NOARGS, _asyncio_Future__schedule_callbacks__doc__},
    221 
    222 static PyObject *
    223 _asyncio_Future__schedule_callbacks_impl(FutureObj *self);
    224 
    225 static PyObject *
    226 _asyncio_Future__schedule_callbacks(FutureObj *self, PyObject *Py_UNUSED(ignored))
    227 {
    228     return _asyncio_Future__schedule_callbacks_impl(self);
    229 }
    230 
    231 PyDoc_STRVAR(_asyncio_Task___init____doc__,
    232 "Task(coro, *, loop=None)\n"
    233 "--\n"
    234 "\n"
    235 "A coroutine wrapped in a Future.");
    236 
    237 static int
    238 _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop);
    239 
    240 static int
    241 _asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs)
    242 {
    243     int return_value = -1;
    244     static const char * const _keywords[] = {"coro", "loop", NULL};
    245     static _PyArg_Parser _parser = {"O|$O:Task", _keywords, 0};
    246     PyObject *coro;
    247     PyObject *loop = NULL;
    248 
    249     if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
    250         &coro, &loop)) {
    251         goto exit;
    252     }
    253     return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop);
    254 
    255 exit:
    256     return return_value;
    257 }
    258 
    259 PyDoc_STRVAR(_asyncio_Task_current_task__doc__,
    260 "current_task($type, /, loop=None)\n"
    261 "--\n"
    262 "\n"
    263 "Return the currently running task in an event loop or None.\n"
    264 "\n"
    265 "By default the current task for the current event loop is returned.\n"
    266 "\n"
    267 "None is returned when called not in the context of a Task.");
    268 
    269 #define _ASYNCIO_TASK_CURRENT_TASK_METHODDEF    \
    270     {"current_task", (PyCFunction)_asyncio_Task_current_task, METH_FASTCALL|METH_CLASS, _asyncio_Task_current_task__doc__},
    271 
    272 static PyObject *
    273 _asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop);
    274 
    275 static PyObject *
    276 _asyncio_Task_current_task(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    277 {
    278     PyObject *return_value = NULL;
    279     static const char * const _keywords[] = {"loop", NULL};
    280     static _PyArg_Parser _parser = {"|O:current_task", _keywords, 0};
    281     PyObject *loop = Py_None;
    282 
    283     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    284         &loop)) {
    285         goto exit;
    286     }
    287     return_value = _asyncio_Task_current_task_impl(type, loop);
    288 
    289 exit:
    290     return return_value;
    291 }
    292 
    293 PyDoc_STRVAR(_asyncio_Task_all_tasks__doc__,
    294 "all_tasks($type, /, loop=None)\n"
    295 "--\n"
    296 "\n"
    297 "Return a set of all tasks for an event loop.\n"
    298 "\n"
    299 "By default all tasks for the current event loop are returned.");
    300 
    301 #define _ASYNCIO_TASK_ALL_TASKS_METHODDEF    \
    302     {"all_tasks", (PyCFunction)_asyncio_Task_all_tasks, METH_FASTCALL|METH_CLASS, _asyncio_Task_all_tasks__doc__},
    303 
    304 static PyObject *
    305 _asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop);
    306 
    307 static PyObject *
    308 _asyncio_Task_all_tasks(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    309 {
    310     PyObject *return_value = NULL;
    311     static const char * const _keywords[] = {"loop", NULL};
    312     static _PyArg_Parser _parser = {"|O:all_tasks", _keywords, 0};
    313     PyObject *loop = Py_None;
    314 
    315     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    316         &loop)) {
    317         goto exit;
    318     }
    319     return_value = _asyncio_Task_all_tasks_impl(type, loop);
    320 
    321 exit:
    322     return return_value;
    323 }
    324 
    325 PyDoc_STRVAR(_asyncio_Task__repr_info__doc__,
    326 "_repr_info($self, /)\n"
    327 "--\n"
    328 "\n");
    329 
    330 #define _ASYNCIO_TASK__REPR_INFO_METHODDEF    \
    331     {"_repr_info", (PyCFunction)_asyncio_Task__repr_info, METH_NOARGS, _asyncio_Task__repr_info__doc__},
    332 
    333 static PyObject *
    334 _asyncio_Task__repr_info_impl(TaskObj *self);
    335 
    336 static PyObject *
    337 _asyncio_Task__repr_info(TaskObj *self, PyObject *Py_UNUSED(ignored))
    338 {
    339     return _asyncio_Task__repr_info_impl(self);
    340 }
    341 
    342 PyDoc_STRVAR(_asyncio_Task_cancel__doc__,
    343 "cancel($self, /)\n"
    344 "--\n"
    345 "\n"
    346 "Request that this task cancel itself.\n"
    347 "\n"
    348 "This arranges for a CancelledError to be thrown into the\n"
    349 "wrapped coroutine on the next cycle through the event loop.\n"
    350 "The coroutine then has a chance to clean up or even deny\n"
    351 "the request using try/except/finally.\n"
    352 "\n"
    353 "Unlike Future.cancel, this does not guarantee that the\n"
    354 "task will be cancelled: the exception might be caught and\n"
    355 "acted upon, delaying cancellation of the task or preventing\n"
    356 "cancellation completely.  The task may also return a value or\n"
    357 "raise a different exception.\n"
    358 "\n"
    359 "Immediately after this method is called, Task.cancelled() will\n"
    360 "not return True (unless the task was already cancelled).  A\n"
    361 "task will be marked as cancelled when the wrapped coroutine\n"
    362 "terminates with a CancelledError exception (even if cancel()\n"
    363 "was not called).");
    364 
    365 #define _ASYNCIO_TASK_CANCEL_METHODDEF    \
    366     {"cancel", (PyCFunction)_asyncio_Task_cancel, METH_NOARGS, _asyncio_Task_cancel__doc__},
    367 
    368 static PyObject *
    369 _asyncio_Task_cancel_impl(TaskObj *self);
    370 
    371 static PyObject *
    372 _asyncio_Task_cancel(TaskObj *self, PyObject *Py_UNUSED(ignored))
    373 {
    374     return _asyncio_Task_cancel_impl(self);
    375 }
    376 
    377 PyDoc_STRVAR(_asyncio_Task_get_stack__doc__,
    378 "get_stack($self, /, *, limit=None)\n"
    379 "--\n"
    380 "\n"
    381 "Return the list of stack frames for this task\'s coroutine.\n"
    382 "\n"
    383 "If the coroutine is not done, this returns the stack where it is\n"
    384 "suspended.  If the coroutine has completed successfully or was\n"
    385 "cancelled, this returns an empty list.  If the coroutine was\n"
    386 "terminated by an exception, this returns the list of traceback\n"
    387 "frames.\n"
    388 "\n"
    389 "The frames are always ordered from oldest to newest.\n"
    390 "\n"
    391 "The optional limit gives the maximum number of frames to\n"
    392 "return; by default all available frames are returned.  Its\n"
    393 "meaning differs depending on whether a stack or a traceback is\n"
    394 "returned: the newest frames of a stack are returned, but the\n"
    395 "oldest frames of a traceback are returned.  (This matches the\n"
    396 "behavior of the traceback module.)\n"
    397 "\n"
    398 "For reasons beyond our control, only one stack frame is\n"
    399 "returned for a suspended coroutine.");
    400 
    401 #define _ASYNCIO_TASK_GET_STACK_METHODDEF    \
    402     {"get_stack", (PyCFunction)_asyncio_Task_get_stack, METH_FASTCALL, _asyncio_Task_get_stack__doc__},
    403 
    404 static PyObject *
    405 _asyncio_Task_get_stack_impl(TaskObj *self, PyObject *limit);
    406 
    407 static PyObject *
    408 _asyncio_Task_get_stack(TaskObj *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    409 {
    410     PyObject *return_value = NULL;
    411     static const char * const _keywords[] = {"limit", NULL};
    412     static _PyArg_Parser _parser = {"|$O:get_stack", _keywords, 0};
    413     PyObject *limit = Py_None;
    414 
    415     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    416         &limit)) {
    417         goto exit;
    418     }
    419     return_value = _asyncio_Task_get_stack_impl(self, limit);
    420 
    421 exit:
    422     return return_value;
    423 }
    424 
    425 PyDoc_STRVAR(_asyncio_Task_print_stack__doc__,
    426 "print_stack($self, /, *, limit=None, file=None)\n"
    427 "--\n"
    428 "\n"
    429 "Print the stack or traceback for this task\'s coroutine.\n"
    430 "\n"
    431 "This produces output similar to that of the traceback module,\n"
    432 "for the frames retrieved by get_stack().  The limit argument\n"
    433 "is passed to get_stack().  The file argument is an I/O stream\n"
    434 "to which the output is written; by default output is written\n"
    435 "to sys.stderr.");
    436 
    437 #define _ASYNCIO_TASK_PRINT_STACK_METHODDEF    \
    438     {"print_stack", (PyCFunction)_asyncio_Task_print_stack, METH_FASTCALL, _asyncio_Task_print_stack__doc__},
    439 
    440 static PyObject *
    441 _asyncio_Task_print_stack_impl(TaskObj *self, PyObject *limit,
    442                                PyObject *file);
    443 
    444 static PyObject *
    445 _asyncio_Task_print_stack(TaskObj *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    446 {
    447     PyObject *return_value = NULL;
    448     static const char * const _keywords[] = {"limit", "file", NULL};
    449     static _PyArg_Parser _parser = {"|$OO:print_stack", _keywords, 0};
    450     PyObject *limit = Py_None;
    451     PyObject *file = Py_None;
    452 
    453     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    454         &limit, &file)) {
    455         goto exit;
    456     }
    457     return_value = _asyncio_Task_print_stack_impl(self, limit, file);
    458 
    459 exit:
    460     return return_value;
    461 }
    462 
    463 PyDoc_STRVAR(_asyncio_Task__step__doc__,
    464 "_step($self, /, exc=None)\n"
    465 "--\n"
    466 "\n");
    467 
    468 #define _ASYNCIO_TASK__STEP_METHODDEF    \
    469     {"_step", (PyCFunction)_asyncio_Task__step, METH_FASTCALL, _asyncio_Task__step__doc__},
    470 
    471 static PyObject *
    472 _asyncio_Task__step_impl(TaskObj *self, PyObject *exc);
    473 
    474 static PyObject *
    475 _asyncio_Task__step(TaskObj *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    476 {
    477     PyObject *return_value = NULL;
    478     static const char * const _keywords[] = {"exc", NULL};
    479     static _PyArg_Parser _parser = {"|O:_step", _keywords, 0};
    480     PyObject *exc = NULL;
    481 
    482     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    483         &exc)) {
    484         goto exit;
    485     }
    486     return_value = _asyncio_Task__step_impl(self, exc);
    487 
    488 exit:
    489     return return_value;
    490 }
    491 
    492 PyDoc_STRVAR(_asyncio_Task__wakeup__doc__,
    493 "_wakeup($self, /, fut)\n"
    494 "--\n"
    495 "\n");
    496 
    497 #define _ASYNCIO_TASK__WAKEUP_METHODDEF    \
    498     {"_wakeup", (PyCFunction)_asyncio_Task__wakeup, METH_FASTCALL, _asyncio_Task__wakeup__doc__},
    499 
    500 static PyObject *
    501 _asyncio_Task__wakeup_impl(TaskObj *self, PyObject *fut);
    502 
    503 static PyObject *
    504 _asyncio_Task__wakeup(TaskObj *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
    505 {
    506     PyObject *return_value = NULL;
    507     static const char * const _keywords[] = {"fut", NULL};
    508     static _PyArg_Parser _parser = {"O:_wakeup", _keywords, 0};
    509     PyObject *fut;
    510 
    511     if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
    512         &fut)) {
    513         goto exit;
    514     }
    515     return_value = _asyncio_Task__wakeup_impl(self, fut);
    516 
    517 exit:
    518     return return_value;
    519 }
    520 /*[clinic end generated code: output=40ca6c9da517da73 input=a9049054013a1b77]*/
    521