blob: 7627849bb886e5418423128ae686adaf5d776032 [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};
30 static _PyArg_Parser _parser = {"|$O:Future", _keywords, 0};
Serhiy Storchakabca49392017-09-03 08:10:14 +030031 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -040032
33 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
34 &loop)) {
35 goto exit;
36 }
37 return_value = _asyncio_Future___init___impl((FutureObj *)self, loop);
38
39exit:
40 return return_value;
41}
42
43PyDoc_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
56static PyObject *
57_asyncio_Future_result_impl(FutureObj *self);
58
59static PyObject *
60_asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored))
61{
62 return _asyncio_Future_result_impl(self);
63}
64
65PyDoc_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
79static PyObject *
80_asyncio_Future_exception_impl(FutureObj *self);
81
82static PyObject *
83_asyncio_Future_exception(FutureObj *self, PyObject *Py_UNUSED(ignored))
84{
85 return _asyncio_Future_exception_impl(self);
86}
87
88PyDoc_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
100PyDoc_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
112PyDoc_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
125PyDoc_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
136PyDoc_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
149static PyObject *
150_asyncio_Future_cancel_impl(FutureObj *self);
151
152static PyObject *
153_asyncio_Future_cancel(FutureObj *self, PyObject *Py_UNUSED(ignored))
154{
155 return _asyncio_Future_cancel_impl(self);
156}
157
158PyDoc_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
167static PyObject *
168_asyncio_Future_cancelled_impl(FutureObj *self);
169
170static PyObject *
171_asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored))
172{
173 return _asyncio_Future_cancelled_impl(self);
174}
175
176PyDoc_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
188static PyObject *
189_asyncio_Future_done_impl(FutureObj *self);
190
191static PyObject *
192_asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored))
193{
194 return _asyncio_Future_done_impl(self);
195}
196
197PyDoc_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
205static PyObject *
206_asyncio_Future__repr_info_impl(FutureObj *self);
207
208static PyObject *
209_asyncio_Future__repr_info(FutureObj *self, PyObject *Py_UNUSED(ignored))
210{
211 return _asyncio_Future__repr_info_impl(self);
212}
213
214PyDoc_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
222static PyObject *
223_asyncio_Future__schedule_callbacks_impl(FutureObj *self);
224
225static PyObject *
226_asyncio_Future__schedule_callbacks(FutureObj *self, PyObject *Py_UNUSED(ignored))
227{
228 return _asyncio_Future__schedule_callbacks_impl(self);
229}
230
231PyDoc_STRVAR(_asyncio_Task___init____doc__,
232"Task(coro, *, loop=None)\n"
233"--\n"
234"\n"
235"A coroutine wrapped in a Future.");
236
237static int
238_asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop);
239
240static 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;
Serhiy Storchakabca49392017-09-03 08:10:14 +0300247 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400248
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
255exit:
256 return return_value;
257}
258
259PyDoc_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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300270 {"current_task", (PyCFunction)_asyncio_Task_current_task, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_current_task__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400271
272static PyObject *
273_asyncio_Task_current_task_impl(PyTypeObject *type, PyObject *loop);
274
275static 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};
Yury Selivanov8d26aa92017-03-02 22:16:33 -0500281 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400282
Victor Stinner3e1fad62017-01-17 01:29:01 +0100283 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400284 &loop)) {
285 goto exit;
286 }
287 return_value = _asyncio_Task_current_task_impl(type, loop);
288
289exit:
290 return return_value;
291}
292
293PyDoc_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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300302 {"all_tasks", (PyCFunction)_asyncio_Task_all_tasks, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, _asyncio_Task_all_tasks__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400303
304static PyObject *
305_asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop);
306
307static 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};
Yury Selivanov8d26aa92017-03-02 22:16:33 -0500313 PyObject *loop = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400314
Victor Stinner3e1fad62017-01-17 01:29:01 +0100315 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400316 &loop)) {
317 goto exit;
318 }
319 return_value = _asyncio_Task_all_tasks_impl(type, loop);
320
321exit:
322 return return_value;
323}
324
325PyDoc_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
333static PyObject *
334_asyncio_Task__repr_info_impl(TaskObj *self);
335
336static PyObject *
337_asyncio_Task__repr_info(TaskObj *self, PyObject *Py_UNUSED(ignored))
338{
339 return _asyncio_Task__repr_info_impl(self);
340}
341
342PyDoc_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
368static PyObject *
369_asyncio_Task_cancel_impl(TaskObj *self);
370
371static PyObject *
372_asyncio_Task_cancel(TaskObj *self, PyObject *Py_UNUSED(ignored))
373{
374 return _asyncio_Task_cancel_impl(self);
375}
376
377PyDoc_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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300402 {"get_stack", (PyCFunction)_asyncio_Task_get_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400403
404static PyObject *
405_asyncio_Task_get_stack_impl(TaskObj *self, PyObject *limit);
406
407static 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
Victor Stinner3e1fad62017-01-17 01:29:01 +0100415 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400416 &limit)) {
417 goto exit;
418 }
419 return_value = _asyncio_Task_get_stack_impl(self, limit);
420
421exit:
422 return return_value;
423}
424
425PyDoc_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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300438 {"print_stack", (PyCFunction)_asyncio_Task_print_stack, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400439
440static PyObject *
441_asyncio_Task_print_stack_impl(TaskObj *self, PyObject *limit,
442 PyObject *file);
443
444static 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
Victor Stinner3e1fad62017-01-17 01:29:01 +0100453 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400454 &limit, &file)) {
455 goto exit;
456 }
457 return_value = _asyncio_Task_print_stack_impl(self, limit, file);
458
459exit:
460 return return_value;
461}
462
463PyDoc_STRVAR(_asyncio_Task__step__doc__,
464"_step($self, /, exc=None)\n"
465"--\n"
466"\n");
467
468#define _ASYNCIO_TASK__STEP_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300469 {"_step", (PyCFunction)_asyncio_Task__step, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task__step__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400470
471static PyObject *
472_asyncio_Task__step_impl(TaskObj *self, PyObject *exc);
473
474static 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};
Serhiy Storchakabca49392017-09-03 08:10:14 +0300480 PyObject *exc = Py_None;
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400481
Victor Stinner3e1fad62017-01-17 01:29:01 +0100482 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400483 &exc)) {
484 goto exit;
485 }
486 return_value = _asyncio_Task__step_impl(self, exc);
487
488exit:
489 return return_value;
490}
491
492PyDoc_STRVAR(_asyncio_Task__wakeup__doc__,
493"_wakeup($self, /, fut)\n"
494"--\n"
495"\n");
496
497#define _ASYNCIO_TASK__WAKEUP_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300498 {"_wakeup", (PyCFunction)_asyncio_Task__wakeup, METH_FASTCALL|METH_KEYWORDS, _asyncio_Task__wakeup__doc__},
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400499
500static PyObject *
501_asyncio_Task__wakeup_impl(TaskObj *self, PyObject *fut);
502
503static 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
Victor Stinner3e1fad62017-01-17 01:29:01 +0100511 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Yury Selivanova0c1ba62016-10-28 12:52:37 -0400512 &fut)) {
513 goto exit;
514 }
515 return_value = _asyncio_Task__wakeup_impl(self, fut);
516
517exit:
518 return return_value;
519}
Serhiy Storchakabca49392017-09-03 08:10:14 +0300520/*[clinic end generated code: output=b92f9cd2b9fb37ef input=a9049054013a1b77]*/