blob: 87669f7c9f32eb834b79c4238ad920491f04cb61 [file] [log] [blame]
Yury Selivanova0c1ba62016-10-28 12:52:37 -04001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
22static int
23_asyncio_Future___init___impl(FutureObj *self, PyObject *loop);
24
25static 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 Storchaka31913912019-03-14 10:32:22 +020030 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 Storchakabca49392017-09-03 08:10:14 +030035 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -040036
Serhiy Storchaka31913912019-03-14 10:32:22 +020037 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 0, 0, argsbuf);
38 if (!fastargs) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -040039 goto exit;
40 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020041 if (!noptargs) {
42 goto skip_optional_kwonly;
43 }
44 loop = fastargs[0];
45skip_optional_kwonly:
Yury Selivanova0c1ba62016-10-28 12:52:37 -040046 return_value = _asyncio_Future___init___impl((FutureObj *)self, loop);
47
48exit:
49 return return_value;
50}
51
52PyDoc_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
65static PyObject *
66_asyncio_Future_result_impl(FutureObj *self);
67
68static PyObject *
69_asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored))
70{
71 return _asyncio_Future_result_impl(self);
72}
73
74PyDoc_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
88static PyObject *
89_asyncio_Future_exception_impl(FutureObj *self);
90
91static PyObject *
92_asyncio_Future_exception(FutureObj *self, PyObject *Py_UNUSED(ignored))
93{
94 return _asyncio_Future_exception_impl(self);
95}
96
97PyDoc_STRVAR(_asyncio_Future_set_result__doc__,
Yury Selivanov0cf16f92017-12-25 10:48:15 -050098"set_result($self, result, /)\n"
Yury Selivanova0c1ba62016-10-28 12:52:37 -040099"--\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
109PyDoc_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
121PyDoc_STRVAR(_asyncio_Future_add_done_callback__doc__,
Yury Selivanovf23746a2018-01-22 19:11:18 -0500122"add_done_callback($self, fn, /, *, context=None)\n"
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400123"--\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 Storchaka4a934d42018-11-27 11:27:36 +0200132 {"add_done_callback", (PyCFunction)(void(*)(void))_asyncio_Future_add_done_callback, METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_add_done_callback__doc__},
Yury Selivanovf23746a2018-01-22 19:11:18 -0500133
134static PyObject *
135_asyncio_Future_add_done_callback_impl(FutureObj *self, PyObject *fn,
136 PyObject *context);
137
138static 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 Storchaka31913912019-03-14 10:32:22 +0200143 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 Selivanovf23746a2018-01-22 19:11:18 -0500146 PyObject *fn;
147 PyObject *context = NULL;
148
Serhiy Storchaka31913912019-03-14 10:32:22 +0200149 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
150 if (!args) {
Yury Selivanovf23746a2018-01-22 19:11:18 -0500151 goto exit;
152 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200153 fn = args[0];
154 if (!noptargs) {
155 goto skip_optional_kwonly;
156 }
157 context = args[1];
158skip_optional_kwonly:
Yury Selivanovf23746a2018-01-22 19:11:18 -0500159 return_value = _asyncio_Future_add_done_callback_impl(self, fn, context);
160
161exit:
162 return return_value;
163}
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400164
165PyDoc_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
176PyDoc_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
189static PyObject *
190_asyncio_Future_cancel_impl(FutureObj *self);
191
192static PyObject *
193_asyncio_Future_cancel(FutureObj *self, PyObject *Py_UNUSED(ignored))
194{
195 return _asyncio_Future_cancel_impl(self);
196}
197
198PyDoc_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
207static PyObject *
208_asyncio_Future_cancelled_impl(FutureObj *self);
209
210static PyObject *
211_asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored))
212{
213 return _asyncio_Future_cancelled_impl(self);
214}
215
216PyDoc_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
228static PyObject *
229_asyncio_Future_done_impl(FutureObj *self);
230
231static PyObject *
232_asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored))
233{
234 return _asyncio_Future_done_impl(self);
235}
236
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500237PyDoc_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
246static PyObject *
247_asyncio_Future_get_loop_impl(FutureObj *self);
248
249static PyObject *
250_asyncio_Future_get_loop(FutureObj *self, PyObject *Py_UNUSED(ignored))
251{
252 return _asyncio_Future_get_loop_impl(self);
253}
254
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400255PyDoc_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
263static PyObject *
264_asyncio_Future__repr_info_impl(FutureObj *self);
265
266static PyObject *
267_asyncio_Future__repr_info(FutureObj *self, PyObject *Py_UNUSED(ignored))
268{
269 return _asyncio_Future__repr_info_impl(self);
270}
271
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400272PyDoc_STRVAR(_asyncio_Task___init____doc__,
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300273"Task(coro, *, loop=None, name=None)\n"
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400274"--\n"
275"\n"
276"A coroutine wrapped in a Future.");
277
278static int
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300279_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
280 PyObject *name);
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400281
282static int
283_asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs)
284{
285 int return_value = -1;
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300286 static const char * const _keywords[] = {"coro", "loop", "name", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200287 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 Selivanova0c1ba62016-10-28 12:52:37 -0400292 PyObject *coro;
Serhiy Storchakabca49392017-09-03 08:10:14 +0300293 PyObject *loop = Py_None;
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300294 PyObject *name = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400295
Serhiy Storchaka31913912019-03-14 10:32:22 +0200296 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
297 if (!fastargs) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400298 goto exit;
299 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200300 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];
311skip_optional_kwonly:
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300312 return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop, name);
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400313
314exit:
315 return return_value;
316}
317
318PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200329 {"current_task", (PyCFunction)(void(*)(void))_asyncio_Task_current_task, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_current_task__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400330
331static PyObject *
332_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop);
333
334static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200335_asyncio_Task_current_task(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400336{
337 PyObject *return_value = NULL;
338 static const char * const _keywords[] = {"loop", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200339 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 Selivanov8d26aa92017-03-02 22:16:33 -0500342 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400343
Serhiy Storchaka31913912019-03-14 10:32:22 +0200344 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
345 if (!args) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400346 goto exit;
347 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200348 if (!noptargs) {
349 goto skip_optional_pos;
350 }
351 loop = args[0];
352skip_optional_pos:
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400353 return_value = _asyncio_Task_current_task_impl(type, loop);
354
355exit:
356 return return_value;
357}
358
359PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200368 {"all_tasks", (PyCFunction)(void(*)(void))_asyncio_Task_all_tasks, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_all_tasks__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400369
370static PyObject *
371_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop);
372
373static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200374_asyncio_Task_all_tasks(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400375{
376 PyObject *return_value = NULL;
377 static const char * const _keywords[] = {"loop", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200378 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 Selivanov8d26aa92017-03-02 22:16:33 -0500381 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400382
Serhiy Storchaka31913912019-03-14 10:32:22 +0200383 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
384 if (!args) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400385 goto exit;
386 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200387 if (!noptargs) {
388 goto skip_optional_pos;
389 }
390 loop = args[0];
391skip_optional_pos:
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400392 return_value = _asyncio_Task_all_tasks_impl(type, loop);
393
394exit:
395 return return_value;
396}
397
398PyDoc_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
406static PyObject *
407_asyncio_Task__repr_info_impl(TaskObj *self);
408
409static PyObject *
410_asyncio_Task__repr_info(TaskObj *self, PyObject *Py_UNUSED(ignored))
411{
412 return _asyncio_Task__repr_info_impl(self);
413}
414
415PyDoc_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
441static PyObject *
442_asyncio_Task_cancel_impl(TaskObj *self);
443
444static PyObject *
445_asyncio_Task_cancel(TaskObj *self, PyObject *Py_UNUSED(ignored))
446{
447 return _asyncio_Task_cancel_impl(self);
448}
449
450PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200475 {"get_stack", (PyCFunction)(void(*)(void))_asyncio_Task_get_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400476
477static PyObject *
478_asyncio_Task_get_stack_impl(TaskObj *self, PyObject *limit);
479
480static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200481_asyncio_Task_get_stack(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400482{
483 PyObject *return_value = NULL;
484 static const char * const _keywords[] = {"limit", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200485 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 Selivanova0c1ba62016-10-28 12:52:37 -0400488 PyObject *limit = Py_None;
489
Serhiy Storchaka31913912019-03-14 10:32:22 +0200490 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
491 if (!args) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400492 goto exit;
493 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200494 if (!noptargs) {
495 goto skip_optional_kwonly;
496 }
497 limit = args[0];
498skip_optional_kwonly:
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400499 return_value = _asyncio_Task_get_stack_impl(self, limit);
500
501exit:
502 return return_value;
503}
504
505PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200518 {"print_stack", (PyCFunction)(void(*)(void))_asyncio_Task_print_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400519
520static PyObject *
521_asyncio_Task_print_stack_impl(TaskObj *self, PyObject *limit,
522 PyObject *file);
523
524static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200525_asyncio_Task_print_stack(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400526{
527 PyObject *return_value = NULL;
528 static const char * const _keywords[] = {"limit", "file", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200529 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 Selivanova0c1ba62016-10-28 12:52:37 -0400532 PyObject *limit = Py_None;
533 PyObject *file = Py_None;
534
Serhiy Storchaka31913912019-03-14 10:32:22 +0200535 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
536 if (!args) {
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400537 goto exit;
538 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200539 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];
549skip_optional_kwonly:
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400550 return_value = _asyncio_Task_print_stack_impl(self, limit, file);
551
552exit:
553 return return_value;
554}
555
Yury Selivanov0cf16f92017-12-25 10:48:15 -0500556PyDoc_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
564PyDoc_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önholmcca4eec2018-08-09 00:06:47 +0300572PyDoc_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
580static PyObject *
581_asyncio_Task_get_name_impl(TaskObj *self);
582
583static PyObject *
584_asyncio_Task_get_name(TaskObj *self, PyObject *Py_UNUSED(ignored))
585{
586 return _asyncio_Task_get_name_impl(self);
587}
588
589PyDoc_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 Selivanova70232f2017-12-13 14:49:42 -0500597PyDoc_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
609static PyObject *
610_asyncio__get_running_loop_impl(PyObject *module);
611
612static PyObject *
613_asyncio__get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
614{
615 return _asyncio__get_running_loop_impl(module);
616}
617
618PyDoc_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
630PyDoc_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
646static PyObject *
647_asyncio_get_event_loop_impl(PyObject *module);
648
649static PyObject *
650_asyncio_get_event_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
651{
652 return _asyncio_get_event_loop_impl(module);
653}
654
655PyDoc_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
666static PyObject *
667_asyncio_get_running_loop_impl(PyObject *module);
668
669static PyObject *
670_asyncio_get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
671{
672 return _asyncio_get_running_loop_impl(module);
673}
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200674
675PyDoc_STRVAR(_asyncio__register_task__doc__,
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500676"_register_task($module, /, task)\n"
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200677"--\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 Storchaka4a934d42018-11-27 11:27:36 +0200684 {"_register_task", (PyCFunction)(void(*)(void))_asyncio__register_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__register_task__doc__},
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200685
686static PyObject *
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500687_asyncio__register_task_impl(PyObject *module, PyObject *task);
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200688
689static PyObject *
690_asyncio__register_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
691{
692 PyObject *return_value = NULL;
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500693 static const char * const _keywords[] = {"task", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200694 static _PyArg_Parser _parser = {NULL, _keywords, "_register_task", 0};
695 PyObject *argsbuf[1];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200696 PyObject *task;
697
Serhiy Storchaka31913912019-03-14 10:32:22 +0200698 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
699 if (!args) {
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200700 goto exit;
701 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200702 task = args[0];
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500703 return_value = _asyncio__register_task_impl(module, task);
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200704
705exit:
706 return return_value;
707}
708
709PyDoc_STRVAR(_asyncio__unregister_task__doc__,
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500710"_unregister_task($module, /, task)\n"
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200711"--\n"
712"\n"
713"Unregister a task.\n"
714"\n"
715"Returns None.");
716
717#define _ASYNCIO__UNREGISTER_TASK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200718 {"_unregister_task", (PyCFunction)(void(*)(void))_asyncio__unregister_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_task__doc__},
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200719
720static PyObject *
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500721_asyncio__unregister_task_impl(PyObject *module, PyObject *task);
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200722
723static PyObject *
724_asyncio__unregister_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
725{
726 PyObject *return_value = NULL;
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500727 static const char * const _keywords[] = {"task", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200728 static _PyArg_Parser _parser = {NULL, _keywords, "_unregister_task", 0};
729 PyObject *argsbuf[1];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200730 PyObject *task;
731
Serhiy Storchaka31913912019-03-14 10:32:22 +0200732 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
733 if (!args) {
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200734 goto exit;
735 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200736 task = args[0];
Yury Selivanovca9b36c2017-12-23 15:04:15 -0500737 return_value = _asyncio__unregister_task_impl(module, task);
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200738
739exit:
740 return return_value;
741}
742
743PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200754 {"_enter_task", (PyCFunction)(void(*)(void))_asyncio__enter_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__enter_task__doc__},
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200755
756static PyObject *
757_asyncio__enter_task_impl(PyObject *module, PyObject *loop, PyObject *task);
758
759static 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 Storchaka31913912019-03-14 10:32:22 +0200764 static _PyArg_Parser _parser = {NULL, _keywords, "_enter_task", 0};
765 PyObject *argsbuf[2];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200766 PyObject *loop;
767 PyObject *task;
768
Serhiy Storchaka31913912019-03-14 10:32:22 +0200769 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
770 if (!args) {
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200771 goto exit;
772 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200773 loop = args[0];
774 task = args[1];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200775 return_value = _asyncio__enter_task_impl(module, loop, task);
776
777exit:
778 return return_value;
779}
780
781PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200792 {"_leave_task", (PyCFunction)(void(*)(void))_asyncio__leave_task, METH_FASTCALL|METH_KEYWORDS, _asyncio__leave_task__doc__},
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200793
794static PyObject *
795_asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task);
796
797static 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 Storchaka31913912019-03-14 10:32:22 +0200802 static _PyArg_Parser _parser = {NULL, _keywords, "_leave_task", 0};
803 PyObject *argsbuf[2];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200804 PyObject *loop;
805 PyObject *task;
806
Serhiy Storchaka31913912019-03-14 10:32:22 +0200807 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
808 if (!args) {
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200809 goto exit;
810 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200811 loop = args[0];
812 task = args[1];
Andrew Svetlov44d1a592017-12-16 21:58:38 +0200813 return_value = _asyncio__leave_task_impl(module, loop, task);
814
815exit:
816 return return_value;
817}
Serhiy Storchaka31913912019-03-14 10:32:22 +0200818/*[clinic end generated code: output=e3b02d96da56e80c input=a9049054013a1b77]*/