Return a new tasklet object. type must be derived from PyTasklet_Type or NULL. func must be a callable object (normal use-case) or NULL, if the tasklet is being used via capture().
Binds a tasklet function to parameters, making it ready to run and inserts in into the runnables queue. Returns 0 if successful or -1 in the case of failure.
Forces task to run immediately. Returns 0 if successful, and -1 in the case of failure.
Forces task to run immediately, soft switching if possible. Returns 1 if the call soft switched, 0 if the call hard switched and -1 in the case of failure.
Removes task from the runnables queue. Be careful! If this tasklet has a C stack attached, you need to either resume running it or kill it. Just dropping it might give an inconsistent system state. Returns 0 if successful, and -1 in the case of failure.
Insert task into the runnables queue, if it isn’t already there. If it is blocked or dead, the function returns -1 and a RuntimeError is raised.
Use of this API function is undocumented and unrecommended.
Deprecated since version 2.5: Proved problematic in production use and are pending removal.
Use of this API function is undocumented and unrecommended.
Deprecated since version 2.5: Proved problematic in production use and are pending removal.
Raises an instance of the klass exception on the self tasklet. klass must be a subclass of Exception. Returns 1 if the call soft switched, 0 if the call hard switched and -1 in the case of failure.
Note
Raising TaskletExit on a tasklet can be done to silently kill it, see PyTasklet_Kill().
Raises TaskletExit on tasklet self. This should result in task being silently killed. Returns 1 if the call soft switched, 0 if the call hard switched and -1 in the case of failure.
Returns 1 if task is atomic, otherwise 0.
Returns 1 if task is currently atomic, otherwise 0. Sets the atomic attribute to the logical value of flag.
Returns 1 if task ignores its nesting level when choosing whether to auto-schedule it, otherwise 0.
Returns the existing value of the ignore_nesting attribute for the tasklet task, setting it to the logical value of flag. If true, the tasklet may be auto-scheduled even if its nesting_level is > 0.
Returns 1 if task is designated as not being allowed to be blocked on a channel, otherwise 0.
Returns 1 if task was already designated as not being allowed to be blocked on a channel, otherwise 0. This attribute is set to the logical value of value.
Returns the current frame that task is executing in, or NULL
Returns 1 if task is the main tasklet, otherwise 0.
Returns 1 if task is the current tasklet, otherwise 0.
Return the current recursion depth of task.
Return the current nesting level of task.
Returns 1 if task is alive (has an associated frame), otherwise 0 if it is dead.
Returns 1 if task is paused, otherwise 0. A tasklet is paused if it is alive, but not scheduled or blocked on a channel.
Returns 1 if task is scheduled, otherwise 0. In the context of this function a tasklet is considered to be scheduled if it is alive, and in the scheduler runnables list or blocked on a channel.
Returns 1 if task can be fully unpickled, otherwise 0. A tasklet can be pickled whether it is fully restorable or not for the purposes of debugging and introspection. A tasklet that has been hard-switched cannot be fully pickled, for instance.
- PyChannelObject* PyChannel_New(PyTypeObject *type)¶
Return a new channel object, or NULL in the case of failure. type must be derived from PyChannel_Type or be NULL, otherwise a TypeError is raised.
Send arg on the channel self. Returns 0 if the operation was successful, or -1 in the case of failure.
Send arg on the channel self, soft switching if possible. Returns 1 if the call soft switched, 0 if the call hard switched and -1 in the case of failure.
Receive on the channel self. Returns a python object if the operation was successful, or NULL in the case of failure.
Receive on the channel self, soft switching if possible. Returns a python object if the operation was successful, Py_UnwindToken if a soft switch occurred, or NULL in the case of failure.
Returns 0 if successful or -1 in the case of failure. An instance of the exception type klass is raised on the first tasklet blocked on channel self.
Returns the first tasklet in the channel self‘s queue, or NULL in the case the queue is empty.
Marks the channel self as closing. No further tasklets can be blocked on the it from this point, unless it is later reopened.
Reopens the channel self. This allows tasklets to once again send and receive on it, if those operations would otherwise block the given tasklet.
Returns 1 if the channel self is marked as closing, otherwise 0.
Returns 1 if the channel self is marked as closing and there are no tasklets blocked on it, otherwise 0.
Returns the current scheduling preference value of self. See channel.preference.
Sets the current scheduling preference value of self. See channel.preference.
Gets the schedule_all override flag for self. See channel.schedule_all.
Sets the schedule_all override flag for self. See channel.schedule_all.
Gets the balance for self. See channel.balance.
Suspend the current tasklet and schedule the next one in the cyclic chain. if remove is nonzero, the current tasklet will be removed from the chain. retval = success NULL = failure
retval = success NULL = failure retval == Py_UnwindToken: soft switched
get the number of runnable tasks, including the current one. -1 = failure
Get the currently running tasklet, that is, “yourself”.
Runs the scheduler until there are no tasklets remaining within it, or until one of the scheduled tasklets runs for timeout VM instructions without blocking. Returns None if the scheduler is empty, a tasklet object if that tasklet timed out, or NULL in the case of failure. If a timed out tasklet is returned, it should be killed or reinserted.
This function can only be called from the main tasklet. During the run, main is suspended, but will be invoked after the action. You will write your exception handler here, since every uncaught exception will be directed to main.
Wraps PyStackless_RunWatchdog(), but allows its behaviour to be customised by the value of flags which may contain any of the following bits:
channel debugging. The callable will be called on every send or receive. Passing NULL removes the handler. Parameters of the callable: channel, tasklet, int sendflag, int willblock -1 = failure
scheduler monitoring. The callable will be called on every scheduling. Passing NULL removes the handler. Parameters of the callable: from, to When a tasklet dies, to is None. After death or when main starts up, from is None. -1 = failure
Scheduler monitoring with a faster interface.
Most of the above functions can be called both from “inside” and “outside” stackless. “inside” means there should be a running (c)frame on top which acts as the “main tasklet”. The functions do a check whether the main tasklet exists, and wrap themselves if it is necessary. The following routines are used to support this, and you may use them as well if you need to make your specific functions always available.