1992-08-04 09:41:02 -03:00
|
|
|
|
|
|
|
/* Thread module */
|
|
|
|
/* Interface to Sjoerd's portable C thread library */
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
#include "Python.h"
|
2009-08-20 06:39:38 -03:00
|
|
|
#include "structmember.h" /* offsetof */
|
1992-08-04 09:41:02 -03:00
|
|
|
|
1994-08-01 08:34:53 -03:00
|
|
|
#ifndef WITH_THREAD
|
1997-05-05 17:56:21 -03:00
|
|
|
#error "Error! The rest of Python is not compiled with thread support."
|
2002-09-05 18:31:04 -03:00
|
|
|
#error "Rerun configure, adding a --with-threads option."
|
1997-05-05 17:56:21 -03:00
|
|
|
#error "Then run `make clean' followed by `make'."
|
1994-08-01 08:34:53 -03:00
|
|
|
#endif
|
|
|
|
|
1998-10-01 17:42:43 -03:00
|
|
|
#include "pythread.h"
|
1992-08-04 09:41:02 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *ThreadError;
|
2009-10-30 14:07:08 -03:00
|
|
|
static long nb_threads = 0;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
|
|
|
/* Lock objects */
|
|
|
|
|
|
|
|
typedef struct {
|
1996-12-16 20:05:22 -04:00
|
|
|
PyObject_HEAD
|
1998-12-21 15:32:43 -04:00
|
|
|
PyThread_type_lock lock_lock;
|
2009-08-20 06:39:38 -03:00
|
|
|
PyObject *in_weakreflist;
|
1992-08-04 09:41:02 -03:00
|
|
|
} lockobject;
|
|
|
|
|
|
|
|
static void
|
2000-07-10 07:03:58 -03:00
|
|
|
lock_dealloc(lockobject *self)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
2009-08-20 06:39:38 -03:00
|
|
|
if (self->in_weakreflist != NULL)
|
|
|
|
PyObject_ClearWeakRefs((PyObject *) self);
|
2010-03-02 20:43:44 -04:00
|
|
|
if (self->lock_lock != NULL) {
|
|
|
|
/* Unlock the lock so it's safe to free it */
|
|
|
|
PyThread_acquire_lock(self->lock_lock, 0);
|
|
|
|
PyThread_release_lock(self->lock_lock);
|
|
|
|
|
|
|
|
PyThread_free_lock(self->lock_lock);
|
|
|
|
}
|
2000-05-03 20:44:39 -03:00
|
|
|
PyObject_Del(self);
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2000-07-10 07:03:58 -03:00
|
|
|
lock_PyThread_acquire_lock(lockobject *self, PyObject *args)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
2002-03-31 11:27:00 -04:00
|
|
|
int i = 1;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
2002-03-31 11:27:00 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "|i:acquire", &i))
|
|
|
|
return NULL;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1998-12-21 15:32:43 -04:00
|
|
|
i = PyThread_acquire_lock(self->lock_lock, i);
|
1996-12-16 20:05:22 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1992-08-04 09:41:02 -03:00
|
|
|
|
2005-06-02 14:07:11 -03:00
|
|
|
return PyBool_FromLong((long)i);
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(acquire_doc,
|
2002-04-07 03:32:21 -03:00
|
|
|
"acquire([wait]) -> None or bool\n\
|
2006-03-09 22:28:35 -04:00
|
|
|
(acquire_lock() is an obsolete synonym)\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
\n\
|
|
|
|
Lock the lock. Without argument, this blocks if the lock is already\n\
|
|
|
|
locked (even by the same thread), waiting for another thread to release\n\
|
2002-04-07 03:32:21 -03:00
|
|
|
the lock, and return None once the lock is acquired.\n\
|
|
|
|
With an argument, this will only block if the argument is true,\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
and the return value reflects whether the lock is acquired.\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
The blocking operation is not interruptible.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2002-03-25 16:46:46 -04:00
|
|
|
lock_PyThread_release_lock(lockobject *self)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
|
|
|
/* Sanity check: the lock must be locked */
|
1998-12-21 15:32:43 -04:00
|
|
|
if (PyThread_acquire_lock(self->lock_lock, 0)) {
|
|
|
|
PyThread_release_lock(self->lock_lock);
|
1996-12-16 20:05:22 -04:00
|
|
|
PyErr_SetString(ThreadError, "release unlocked lock");
|
1992-08-04 09:41:02 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-12-21 15:32:43 -04:00
|
|
|
PyThread_release_lock(self->lock_lock);
|
1996-12-16 20:05:22 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(release_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"release()\n\
|
2006-03-09 22:28:35 -04:00
|
|
|
(release_lock() is an obsolete synonym)\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
\n\
|
|
|
|
Release the lock, allowing another thread that is blocked waiting for\n\
|
|
|
|
the lock to acquire the lock. The lock must be in the locked state,\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
but it needn't be locked by the same thread that unlocks it.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2002-03-25 16:46:46 -04:00
|
|
|
lock_locked_lock(lockobject *self)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
1998-12-21 15:32:43 -04:00
|
|
|
if (PyThread_acquire_lock(self->lock_lock, 0)) {
|
|
|
|
PyThread_release_lock(self->lock_lock);
|
2002-04-07 03:32:21 -03:00
|
|
|
return PyBool_FromLong(0L);
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
2002-04-07 03:32:21 -03:00
|
|
|
return PyBool_FromLong(1L);
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(locked_doc,
|
2002-04-07 03:32:21 -03:00
|
|
|
"locked() -> bool\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
(locked_lock() is an obsolete synonym)\n\
|
|
|
|
\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
Return whether the lock is in the locked state.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyMethodDef lock_methods[] = {
|
2000-08-02 23:34:44 -03:00
|
|
|
{"acquire_lock", (PyCFunction)lock_PyThread_acquire_lock,
|
2002-03-31 11:27:00 -04:00
|
|
|
METH_VARARGS, acquire_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"acquire", (PyCFunction)lock_PyThread_acquire_lock,
|
2002-03-31 11:27:00 -04:00
|
|
|
METH_VARARGS, acquire_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"release_lock", (PyCFunction)lock_PyThread_release_lock,
|
2002-03-25 16:46:46 -04:00
|
|
|
METH_NOARGS, release_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"release", (PyCFunction)lock_PyThread_release_lock,
|
2002-03-25 17:05:50 -04:00
|
|
|
METH_NOARGS, release_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"locked_lock", (PyCFunction)lock_locked_lock,
|
2002-03-25 16:46:46 -04:00
|
|
|
METH_NOARGS, locked_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"locked", (PyCFunction)lock_locked_lock,
|
2002-03-25 17:05:50 -04:00
|
|
|
METH_NOARGS, locked_doc},
|
2006-02-28 17:57:43 -04:00
|
|
|
{"__enter__", (PyCFunction)lock_PyThread_acquire_lock,
|
|
|
|
METH_VARARGS, acquire_doc},
|
2006-03-09 22:28:35 -04:00
|
|
|
{"__exit__", (PyCFunction)lock_PyThread_release_lock,
|
|
|
|
METH_VARARGS, release_doc},
|
2009-05-24 20:13:32 -03:00
|
|
|
{NULL} /* sentinel */
|
1992-08-04 09:41:02 -03:00
|
|
|
};
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyTypeObject Locktype = {
|
2007-07-21 03:55:02 -03:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
2001-12-08 14:02:58 -04:00
|
|
|
"thread.lock", /*tp_name*/
|
1994-08-01 08:34:53 -03:00
|
|
|
sizeof(lockobject), /*tp_size*/
|
|
|
|
0, /*tp_itemsize*/
|
1992-08-04 09:41:02 -03:00
|
|
|
/* methods */
|
1994-08-01 08:34:53 -03:00
|
|
|
(destructor)lock_dealloc, /*tp_dealloc*/
|
|
|
|
0, /*tp_print*/
|
2009-05-24 20:13:32 -03:00
|
|
|
0, /*tp_getattr*/
|
1994-08-01 08:34:53 -03:00
|
|
|
0, /*tp_setattr*/
|
|
|
|
0, /*tp_compare*/
|
|
|
|
0, /*tp_repr*/
|
2009-05-24 20:13:32 -03:00
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
0, /* tp_hash */
|
|
|
|
0, /* tp_call */
|
|
|
|
0, /* tp_str */
|
|
|
|
0, /* tp_getattro */
|
|
|
|
0, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
2009-08-20 06:39:38 -03:00
|
|
|
Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
|
2009-05-24 20:13:32 -03:00
|
|
|
0, /* tp_doc */
|
|
|
|
0, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
0, /* tp_richcompare */
|
2009-08-20 06:39:38 -03:00
|
|
|
offsetof(lockobject, in_weakreflist), /* tp_weaklistoffset */
|
2009-05-24 20:13:32 -03:00
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
|
|
|
lock_methods, /* tp_methods */
|
1992-08-04 09:41:02 -03:00
|
|
|
};
|
|
|
|
|
2006-04-12 01:08:46 -03:00
|
|
|
static lockobject *
|
|
|
|
newlockobject(void)
|
|
|
|
{
|
|
|
|
lockobject *self;
|
|
|
|
self = PyObject_New(lockobject, &Locktype);
|
|
|
|
if (self == NULL)
|
|
|
|
return NULL;
|
|
|
|
self->lock_lock = PyThread_allocate_lock();
|
2009-08-20 06:39:38 -03:00
|
|
|
self->in_weakreflist = NULL;
|
2006-04-12 01:08:46 -03:00
|
|
|
if (self->lock_lock == NULL) {
|
2010-03-02 20:43:44 -04:00
|
|
|
Py_DECREF(self);
|
2006-04-12 01:08:46 -03:00
|
|
|
PyErr_SetString(ThreadError, "can't allocate lock");
|
2010-03-02 20:43:44 -04:00
|
|
|
return NULL;
|
2006-04-12 01:08:46 -03:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-07-14 16:11:50 -03:00
|
|
|
/* Thread-local objects */
|
|
|
|
|
|
|
|
#include "structmember.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2005-06-15 09:48:40 -03:00
|
|
|
PyObject_HEAD
|
|
|
|
PyObject *key;
|
|
|
|
PyObject *args;
|
|
|
|
PyObject *kw;
|
|
|
|
PyObject *dict;
|
2004-07-14 16:11:50 -03:00
|
|
|
} localobject;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
|
|
|
{
|
2005-06-15 09:48:40 -03:00
|
|
|
localobject *self;
|
|
|
|
PyObject *tdict;
|
|
|
|
|
|
|
|
if (type->tp_init == PyBaseObject_Type.tp_init
|
|
|
|
&& ((args && PyObject_IsTrue(args))
|
|
|
|
|| (kw && PyObject_IsTrue(kw)))) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"Initialization arguments are not supported");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
self = (localobject *)type->tp_alloc(type, 0);
|
|
|
|
if (self == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
Py_XINCREF(args);
|
|
|
|
self->args = args;
|
|
|
|
Py_XINCREF(kw);
|
|
|
|
self->kw = kw;
|
|
|
|
self->dict = NULL; /* making sure */
|
2008-06-09 01:58:54 -03:00
|
|
|
self->key = PyString_FromFormat("thread.local.%p", self);
|
2005-06-15 09:48:40 -03:00
|
|
|
if (self->key == NULL)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
self->dict = PyDict_New();
|
|
|
|
if (self->dict == NULL)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
tdict = PyThreadState_GetDict();
|
|
|
|
if (tdict == NULL) {
|
|
|
|
PyErr_SetString(PyExc_SystemError,
|
|
|
|
"Couldn't get thread-state dictionary");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PyDict_SetItem(tdict, self->key, self->dict) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return (PyObject *)self;
|
|
|
|
|
|
|
|
err:
|
|
|
|
Py_DECREF(self);
|
|
|
|
return NULL;
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
local_traverse(localobject *self, visitproc visit, void *arg)
|
|
|
|
{
|
2005-06-15 09:48:40 -03:00
|
|
|
Py_VISIT(self->args);
|
|
|
|
Py_VISIT(self->kw);
|
|
|
|
Py_VISIT(self->dict);
|
2004-07-14 16:11:50 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
local_clear(localobject *self)
|
|
|
|
{
|
2005-06-15 09:48:40 -03:00
|
|
|
Py_CLEAR(self->args);
|
|
|
|
Py_CLEAR(self->kw);
|
|
|
|
Py_CLEAR(self->dict);
|
|
|
|
return 0;
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
local_dealloc(localobject *self)
|
|
|
|
{
|
2005-06-15 09:48:40 -03:00
|
|
|
PyThreadState *tstate;
|
|
|
|
if (self->key
|
|
|
|
&& (tstate = PyThreadState_Get())
|
|
|
|
&& tstate->interp) {
|
|
|
|
for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
|
|
|
|
tstate;
|
|
|
|
tstate = PyThreadState_Next(tstate))
|
|
|
|
if (tstate->dict &&
|
|
|
|
PyDict_GetItem(tstate->dict, self->key))
|
|
|
|
PyDict_DelItem(tstate->dict, self->key);
|
|
|
|
}
|
|
|
|
|
2009-09-29 01:32:44 -03:00
|
|
|
Py_XDECREF(self->key);
|
2005-06-15 09:48:40 -03:00
|
|
|
local_clear(self);
|
2007-12-18 22:37:44 -04:00
|
|
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_ldict(localobject *self)
|
|
|
|
{
|
|
|
|
PyObject *tdict, *ldict;
|
|
|
|
|
|
|
|
tdict = PyThreadState_GetDict();
|
2005-06-15 09:48:40 -03:00
|
|
|
if (tdict == NULL) {
|
|
|
|
PyErr_SetString(PyExc_SystemError,
|
|
|
|
"Couldn't get thread-state dictionary");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldict = PyDict_GetItem(tdict, self->key);
|
|
|
|
if (ldict == NULL) {
|
|
|
|
ldict = PyDict_New(); /* we own ldict */
|
|
|
|
|
|
|
|
if (ldict == NULL)
|
|
|
|
return NULL;
|
|
|
|
else {
|
|
|
|
int i = PyDict_SetItem(tdict, self->key, ldict);
|
2006-03-08 08:24:33 -04:00
|
|
|
Py_DECREF(ldict); /* now ldict is borrowed */
|
2005-06-15 09:48:40 -03:00
|
|
|
if (i < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_CLEAR(self->dict);
|
|
|
|
Py_INCREF(ldict);
|
|
|
|
self->dict = ldict; /* still borrowed */
|
|
|
|
|
2007-12-18 22:37:44 -04:00
|
|
|
if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init &&
|
|
|
|
Py_TYPE(self)->tp_init((PyObject*)self,
|
2005-06-15 09:48:40 -03:00
|
|
|
self->args, self->kw) < 0) {
|
|
|
|
/* we need to get rid of ldict from thread so
|
|
|
|
we create a new one the next time we do an attr
|
|
|
|
acces */
|
|
|
|
PyDict_DelItem(tdict, self->key);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-06-30 19:42:40 -03:00
|
|
|
|
|
|
|
/* The call to tp_init above may have caused another thread to run.
|
|
|
|
Install our ldict again. */
|
|
|
|
if (self->dict != ldict) {
|
2005-06-15 09:48:40 -03:00
|
|
|
Py_CLEAR(self->dict);
|
|
|
|
Py_INCREF(ldict);
|
|
|
|
self->dict = ldict;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ldict;
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
local_setattro(localobject *self, PyObject *name, PyObject *v)
|
|
|
|
{
|
|
|
|
PyObject *ldict;
|
2005-06-15 09:48:40 -03:00
|
|
|
|
|
|
|
ldict = _ldict(self);
|
|
|
|
if (ldict == NULL)
|
|
|
|
return -1;
|
2004-07-14 16:11:50 -03:00
|
|
|
|
2005-06-15 09:48:40 -03:00
|
|
|
return PyObject_GenericSetAttr((PyObject *)self, name, v);
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
local_getdict(localobject *self, void *closure)
|
|
|
|
{
|
2005-06-15 09:48:40 -03:00
|
|
|
if (self->dict == NULL) {
|
|
|
|
PyErr_SetString(PyExc_AttributeError, "__dict__");
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-14 16:11:50 -03:00
|
|
|
|
2005-06-15 09:48:40 -03:00
|
|
|
Py_INCREF(self->dict);
|
|
|
|
return self->dict;
|
2004-07-14 16:11:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyGetSetDef local_getset[] = {
|
2005-06-15 09:48:40 -03:00
|
|
|
{"__dict__", (getter)local_getdict, (setter)NULL,
|
|
|
|
"Local-data dictionary", NULL},
|
|
|
|
{NULL} /* Sentinel */
|
2004-07-14 16:11:50 -03:00
|
|
|
};
|
|
|
|
|
2006-04-12 01:08:46 -03:00
|
|
|
static PyObject *local_getattro(localobject *, PyObject *);
|
|
|
|
|
2004-07-14 16:11:50 -03:00
|
|
|
static PyTypeObject localtype = {
|
2007-07-21 03:55:02 -03:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2004-07-14 16:11:50 -03:00
|
|
|
/* tp_name */ "thread._local",
|
|
|
|
/* tp_basicsize */ sizeof(localobject),
|
|
|
|
/* tp_itemsize */ 0,
|
|
|
|
/* tp_dealloc */ (destructor)local_dealloc,
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_print */ 0,
|
|
|
|
/* tp_getattr */ 0,
|
|
|
|
/* tp_setattr */ 0,
|
|
|
|
/* tp_compare */ 0,
|
|
|
|
/* tp_repr */ 0,
|
2004-07-14 16:11:50 -03:00
|
|
|
/* tp_as_number */ 0,
|
|
|
|
/* tp_as_sequence */ 0,
|
|
|
|
/* tp_as_mapping */ 0,
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_hash */ 0,
|
|
|
|
/* tp_call */ 0,
|
|
|
|
/* tp_str */ 0,
|
2005-06-15 09:48:40 -03:00
|
|
|
/* tp_getattro */ (getattrofunc)local_getattro,
|
|
|
|
/* tp_setattro */ (setattrofunc)local_setattro,
|
|
|
|
/* tp_as_buffer */ 0,
|
|
|
|
/* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
2004-07-14 16:11:50 -03:00
|
|
|
/* tp_doc */ "Thread-local data",
|
2005-06-15 09:48:40 -03:00
|
|
|
/* tp_traverse */ (traverseproc)local_traverse,
|
|
|
|
/* tp_clear */ (inquiry)local_clear,
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_richcompare */ 0,
|
|
|
|
/* tp_weaklistoffset */ 0,
|
|
|
|
/* tp_iter */ 0,
|
|
|
|
/* tp_iternext */ 0,
|
2005-06-15 09:48:40 -03:00
|
|
|
/* tp_methods */ 0,
|
|
|
|
/* tp_members */ 0,
|
|
|
|
/* tp_getset */ local_getset,
|
|
|
|
/* tp_base */ 0,
|
|
|
|
/* tp_dict */ 0, /* internal use */
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_descr_get */ 0,
|
|
|
|
/* tp_descr_set */ 0,
|
2005-06-15 09:48:40 -03:00
|
|
|
/* tp_dictoffset */ offsetof(localobject, dict),
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_init */ 0,
|
|
|
|
/* tp_alloc */ 0,
|
|
|
|
/* tp_new */ local_new,
|
2004-07-14 16:11:50 -03:00
|
|
|
/* tp_free */ 0, /* Low-level free-mem routine */
|
2006-03-30 07:58:57 -04:00
|
|
|
/* tp_is_gc */ 0, /* For PyObject_IS_GC */
|
2004-07-14 16:11:50 -03:00
|
|
|
};
|
|
|
|
|
2006-04-12 01:08:46 -03:00
|
|
|
static PyObject *
|
|
|
|
local_getattro(localobject *self, PyObject *name)
|
|
|
|
{
|
|
|
|
PyObject *ldict, *value;
|
|
|
|
|
|
|
|
ldict = _ldict(self);
|
|
|
|
if (ldict == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2007-12-18 22:37:44 -04:00
|
|
|
if (Py_TYPE(self) != &localtype)
|
2006-04-12 01:08:46 -03:00
|
|
|
/* use generic lookup for subtypes */
|
|
|
|
return PyObject_GenericGetAttr((PyObject *)self, name);
|
|
|
|
|
|
|
|
/* Optimization: just look in dict ourselves */
|
|
|
|
value = PyDict_GetItem(ldict, name);
|
|
|
|
if (value == NULL)
|
|
|
|
/* Fall back on generic to get __class__ and __dict__ */
|
|
|
|
return PyObject_GenericGetAttr((PyObject *)self, name);
|
|
|
|
|
|
|
|
Py_INCREF(value);
|
|
|
|
return value;
|
|
|
|
}
|
1992-08-04 09:41:02 -03:00
|
|
|
|
|
|
|
/* Module functions */
|
|
|
|
|
1997-05-05 17:56:21 -03:00
|
|
|
struct bootstate {
|
|
|
|
PyInterpreterState *interp;
|
|
|
|
PyObject *func;
|
|
|
|
PyObject *args;
|
|
|
|
PyObject *keyw;
|
2010-03-03 19:20:25 -04:00
|
|
|
PyThreadState *tstate;
|
1997-05-05 17:56:21 -03:00
|
|
|
};
|
|
|
|
|
1992-08-04 09:41:02 -03:00
|
|
|
static void
|
2000-07-10 07:03:58 -03:00
|
|
|
t_bootstrap(void *boot_raw)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
1997-05-05 17:56:21 -03:00
|
|
|
struct bootstate *boot = (struct bootstate *) boot_raw;
|
2005-06-20 13:52:57 -03:00
|
|
|
PyThreadState *tstate;
|
1997-05-05 17:56:21 -03:00
|
|
|
PyObject *res;
|
1992-08-17 05:59:08 -03:00
|
|
|
|
2010-03-03 19:20:25 -04:00
|
|
|
tstate = boot->tstate;
|
|
|
|
tstate->thread_id = PyThread_get_thread_ident();
|
|
|
|
_PyThreadState_Init(tstate);
|
2005-06-20 13:52:57 -03:00
|
|
|
PyEval_AcquireThread(tstate);
|
2009-10-30 14:07:08 -03:00
|
|
|
nb_threads++;
|
1997-05-05 17:56:21 -03:00
|
|
|
res = PyEval_CallObjectWithKeywords(
|
|
|
|
boot->func, boot->args, boot->keyw);
|
1992-08-04 09:41:02 -03:00
|
|
|
if (res == NULL) {
|
1998-05-28 01:35:12 -03:00
|
|
|
if (PyErr_ExceptionMatches(PyExc_SystemExit))
|
1996-12-16 20:05:22 -04:00
|
|
|
PyErr_Clear();
|
1995-03-17 06:42:27 -04:00
|
|
|
else {
|
2003-04-29 16:44:05 -03:00
|
|
|
PyObject *file;
|
|
|
|
PySys_WriteStderr(
|
|
|
|
"Unhandled exception in thread started by ");
|
|
|
|
file = PySys_GetObject("stderr");
|
|
|
|
if (file)
|
|
|
|
PyFile_WriteObject(boot->func, file, 0);
|
|
|
|
else
|
|
|
|
PyObject_Print(boot->func, stderr, 0);
|
|
|
|
PySys_WriteStderr("\n");
|
1998-02-06 18:32:08 -04:00
|
|
|
PyErr_PrintEx(0);
|
1995-03-17 06:42:27 -04:00
|
|
|
}
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
1995-01-02 15:30:30 -04:00
|
|
|
else
|
1996-12-16 20:05:22 -04:00
|
|
|
Py_DECREF(res);
|
2003-04-29 16:44:05 -03:00
|
|
|
Py_DECREF(boot->func);
|
|
|
|
Py_DECREF(boot->args);
|
|
|
|
Py_XDECREF(boot->keyw);
|
|
|
|
PyMem_DEL(boot_raw);
|
2009-10-30 14:07:08 -03:00
|
|
|
nb_threads--;
|
2005-06-20 13:52:57 -03:00
|
|
|
PyThreadState_Clear(tstate);
|
|
|
|
PyThreadState_DeleteCurrent();
|
1998-08-04 19:53:56 -03:00
|
|
|
PyThread_exit_thread();
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2000-07-10 07:03:58 -03:00
|
|
|
thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
2000-09-01 17:47:58 -03:00
|
|
|
PyObject *func, *args, *keyw = NULL;
|
1997-05-05 17:56:21 -03:00
|
|
|
struct bootstate *boot;
|
2001-10-16 18:13:49 -03:00
|
|
|
long ident;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
2006-05-29 18:04:52 -03:00
|
|
|
if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3,
|
|
|
|
&func, &args, &keyw))
|
1997-05-05 17:56:21 -03:00
|
|
|
return NULL;
|
|
|
|
if (!PyCallable_Check(func)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"first arg must be callable");
|
1992-08-04 09:41:02 -03:00
|
|
|
return NULL;
|
1997-05-05 17:56:21 -03:00
|
|
|
}
|
|
|
|
if (!PyTuple_Check(args)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
2000-09-01 17:47:58 -03:00
|
|
|
"2nd arg must be a tuple");
|
1997-05-05 17:56:21 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (keyw != NULL && !PyDict_Check(keyw)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"optional 3rd arg must be a dictionary");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
boot = PyMem_NEW(struct bootstate, 1);
|
|
|
|
if (boot == NULL)
|
|
|
|
return PyErr_NoMemory();
|
2004-03-24 18:22:12 -04:00
|
|
|
boot->interp = PyThreadState_GET()->interp;
|
1997-05-05 17:56:21 -03:00
|
|
|
boot->func = func;
|
|
|
|
boot->args = args;
|
|
|
|
boot->keyw = keyw;
|
2010-03-03 19:20:25 -04:00
|
|
|
boot->tstate = _PyThreadState_Prealloc(boot->interp);
|
|
|
|
if (boot->tstate == NULL) {
|
|
|
|
PyMem_DEL(boot);
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
}
|
1997-05-05 17:56:21 -03:00
|
|
|
Py_INCREF(func);
|
1996-12-16 20:05:22 -04:00
|
|
|
Py_INCREF(args);
|
1997-05-05 17:56:21 -03:00
|
|
|
Py_XINCREF(keyw);
|
|
|
|
PyEval_InitThreads(); /* Start the interpreter's thread-awareness */
|
2001-10-16 18:13:49 -03:00
|
|
|
ident = PyThread_start_new_thread(t_bootstrap, (void*) boot);
|
|
|
|
if (ident == -1) {
|
2005-02-19 23:02:16 -04:00
|
|
|
PyErr_SetString(ThreadError, "can't start new thread");
|
1997-05-05 17:56:21 -03:00
|
|
|
Py_DECREF(func);
|
|
|
|
Py_DECREF(args);
|
|
|
|
Py_XDECREF(keyw);
|
2010-03-03 19:20:25 -04:00
|
|
|
PyThreadState_Clear(boot->tstate);
|
1997-05-05 17:56:21 -03:00
|
|
|
PyMem_DEL(boot);
|
1992-08-04 09:41:02 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-16 18:13:49 -03:00
|
|
|
return PyInt_FromLong(ident);
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(start_new_doc,
|
2001-10-05 09:24:15 -03:00
|
|
|
"start_new_thread(function, args[, kwargs])\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
(start_new() is an obsolete synonym)\n\
|
|
|
|
\n\
|
2001-10-16 18:13:49 -03:00
|
|
|
Start a new thread and return its identifier. The thread will call the\n\
|
|
|
|
function with positional arguments from the tuple args and keyword arguments\n\
|
|
|
|
taken from the optional dictionary kwargs. The thread exits when the\n\
|
|
|
|
function returns; the return value is ignored. The thread will also exit\n\
|
|
|
|
when the function raises an unhandled exception; a stack trace will be\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
printed unless the exception is SystemExit.\n");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2002-03-25 16:46:46 -04:00
|
|
|
thread_PyThread_exit_thread(PyObject *self)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
1996-12-16 20:05:22 -04:00
|
|
|
PyErr_SetNone(PyExc_SystemExit);
|
1995-03-17 06:42:27 -04:00
|
|
|
return NULL;
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(exit_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"exit()\n\
|
1998-12-21 15:32:43 -04:00
|
|
|
(PyThread_exit_thread() is an obsolete synonym)\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
\n\
|
|
|
|
This is synonymous to ``raise SystemExit''. It will cause the current\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
thread to exit silently unless the exception is caught.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
2003-06-13 18:59:45 -03:00
|
|
|
static PyObject *
|
2003-06-16 15:51:28 -03:00
|
|
|
thread_PyThread_interrupt_main(PyObject * self)
|
2003-06-13 18:59:45 -03:00
|
|
|
{
|
|
|
|
PyErr_SetInterrupt();
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(interrupt_doc,
|
|
|
|
"interrupt_main()\n\
|
|
|
|
\n\
|
|
|
|
Raise a KeyboardInterrupt in the main thread.\n\
|
2003-06-16 15:51:28 -03:00
|
|
|
A subthread can use this function to interrupt the main thread."
|
2003-06-13 18:59:45 -03:00
|
|
|
);
|
|
|
|
|
2006-04-12 01:08:46 -03:00
|
|
|
static lockobject *newlockobject(void);
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2002-03-25 16:46:46 -04:00
|
|
|
thread_PyThread_allocate_lock(PyObject *self)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
1996-12-16 20:05:22 -04:00
|
|
|
return (PyObject *) newlockobject();
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(allocate_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"allocate_lock() -> lock object\n\
|
|
|
|
(allocate() is an obsolete synonym)\n\
|
|
|
|
\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
Create a new lock object. See LockType.__doc__ for information about locks.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyObject *
|
2002-03-25 16:46:46 -04:00
|
|
|
thread_get_ident(PyObject *self)
|
1994-08-01 08:34:53 -03:00
|
|
|
{
|
|
|
|
long ident;
|
1998-12-21 15:32:43 -04:00
|
|
|
ident = PyThread_get_thread_ident();
|
1994-08-01 08:34:53 -03:00
|
|
|
if (ident == -1) {
|
1996-12-16 20:05:22 -04:00
|
|
|
PyErr_SetString(ThreadError, "no current thread ident");
|
1994-08-01 08:34:53 -03:00
|
|
|
return NULL;
|
|
|
|
}
|
1996-12-16 20:05:22 -04:00
|
|
|
return PyInt_FromLong(ident);
|
1994-08-01 08:34:53 -03:00
|
|
|
}
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(get_ident_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"get_ident() -> integer\n\
|
|
|
|
\n\
|
|
|
|
Return a non-zero integer that uniquely identifies the current thread\n\
|
|
|
|
amongst other threads that exist simultaneously.\n\
|
|
|
|
This may be used to identify per-thread resources.\n\
|
|
|
|
Even though on some platforms threads identities may appear to be\n\
|
|
|
|
allocated consecutive numbers starting at 1, this behavior should not\n\
|
|
|
|
be relied upon, and the number should be seen purely as a magic cookie.\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
A thread's identity may be reused for another thread after it exits.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
2009-10-30 14:07:08 -03:00
|
|
|
static PyObject *
|
|
|
|
thread__count(PyObject *self)
|
|
|
|
{
|
|
|
|
return PyInt_FromLong(nb_threads);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_count_doc,
|
|
|
|
"_count() -> integer\n\
|
|
|
|
\n\
|
2009-10-30 19:19:09 -03:00
|
|
|
\
|
|
|
|
Return the number of currently running Python threads, excluding \n\
|
|
|
|
the main thread. The returned number comprises all threads created\n\
|
|
|
|
through `start_new_thread()` as well as `threading.Thread`, and not\n\
|
|
|
|
yet finished.\n\
|
|
|
|
\n\
|
|
|
|
This function is meant for internal and specialized purposes only.\n\
|
|
|
|
In most applications `threading.enumerate()` should be used instead.");
|
2009-10-30 14:07:08 -03:00
|
|
|
|
2006-06-13 12:04:24 -03:00
|
|
|
static PyObject *
|
|
|
|
thread_stack_size(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
size_t old_size;
|
|
|
|
Py_ssize_t new_size = 0;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (new_size < 0) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"size must be 0 or a positive value");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_size = PyThread_get_stacksize();
|
|
|
|
|
|
|
|
rc = PyThread_set_stacksize((size_t) new_size);
|
|
|
|
if (rc == -1) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"size not valid: %zd bytes",
|
|
|
|
new_size);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (rc == -2) {
|
|
|
|
PyErr_SetString(ThreadError,
|
|
|
|
"setting stack size not supported");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyInt_FromSsize_t((Py_ssize_t) old_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(stack_size_doc,
|
|
|
|
"stack_size([size]) -> size\n\
|
|
|
|
\n\
|
|
|
|
Return the thread stack size used when creating new threads. The\n\
|
|
|
|
optional size argument specifies the stack size (in bytes) to be used\n\
|
|
|
|
for subsequently created threads, and must be 0 (use platform or\n\
|
|
|
|
configured default) or a positive integer value of at least 32,768 (32k).\n\
|
|
|
|
If changing the thread stack size is unsupported, a ThreadError\n\
|
|
|
|
exception is raised. If the specified size is invalid, a ValueError\n\
|
|
|
|
exception is raised, and the stack size is unmodified. 32k bytes\n\
|
|
|
|
currently the minimum supported stack size value to guarantee\n\
|
|
|
|
sufficient stack space for the interpreter itself.\n\
|
|
|
|
\n\
|
|
|
|
Note that some platforms may have particular restrictions on values for\n\
|
|
|
|
the stack size, such as requiring a minimum stack size larger than 32kB or\n\
|
|
|
|
requiring allocation in multiples of the system memory page size\n\
|
|
|
|
- platform documentation should be referred to for more information\n\
|
|
|
|
(4kB pages are common; using multiples of 4096 for the stack size is\n\
|
|
|
|
the suggested approach in the absence of more specific information).");
|
|
|
|
|
1996-12-16 20:05:22 -04:00
|
|
|
static PyMethodDef thread_methods[] = {
|
2000-08-02 23:06:16 -03:00
|
|
|
{"start_new_thread", (PyCFunction)thread_PyThread_start_new_thread,
|
|
|
|
METH_VARARGS,
|
1998-06-27 15:21:06 -03:00
|
|
|
start_new_doc},
|
2000-08-02 23:06:16 -03:00
|
|
|
{"start_new", (PyCFunction)thread_PyThread_start_new_thread,
|
|
|
|
METH_VARARGS,
|
1998-06-27 15:21:06 -03:00
|
|
|
start_new_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"allocate_lock", (PyCFunction)thread_PyThread_allocate_lock,
|
2002-03-25 16:46:46 -04:00
|
|
|
METH_NOARGS, allocate_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"allocate", (PyCFunction)thread_PyThread_allocate_lock,
|
2002-03-26 10:52:00 -04:00
|
|
|
METH_NOARGS, allocate_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"exit_thread", (PyCFunction)thread_PyThread_exit_thread,
|
2002-03-25 16:46:46 -04:00
|
|
|
METH_NOARGS, exit_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"exit", (PyCFunction)thread_PyThread_exit_thread,
|
2002-03-26 10:52:00 -04:00
|
|
|
METH_NOARGS, exit_doc},
|
2003-06-16 15:51:28 -03:00
|
|
|
{"interrupt_main", (PyCFunction)thread_PyThread_interrupt_main,
|
2003-06-13 18:59:45 -03:00
|
|
|
METH_NOARGS, interrupt_doc},
|
2000-08-02 23:34:44 -03:00
|
|
|
{"get_ident", (PyCFunction)thread_get_ident,
|
2002-03-25 16:46:46 -04:00
|
|
|
METH_NOARGS, get_ident_doc},
|
2009-10-30 14:07:08 -03:00
|
|
|
{"_count", (PyCFunction)thread__count,
|
|
|
|
METH_NOARGS, _count_doc},
|
2006-06-13 12:04:24 -03:00
|
|
|
{"stack_size", (PyCFunction)thread_stack_size,
|
|
|
|
METH_VARARGS,
|
|
|
|
stack_size_doc},
|
1992-08-04 09:41:02 -03:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialization function */
|
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(thread_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"This module provides primitive operations to write multi-threaded programs.\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
The 'threading' module provides a more convenient interface.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
2002-06-13 17:33:02 -03:00
|
|
|
PyDoc_STRVAR(lock_doc,
|
1998-06-27 15:21:06 -03:00
|
|
|
"A lock object is a synchronization primitive. To create a lock,\n\
|
1998-12-21 15:32:43 -04:00
|
|
|
call the PyThread_allocate_lock() function. Methods are:\n\
|
1998-06-27 15:21:06 -03:00
|
|
|
\n\
|
|
|
|
acquire() -- lock the lock, possibly blocking until it can be obtained\n\
|
|
|
|
release() -- unlock of the lock\n\
|
|
|
|
locked() -- test whether the lock is currently locked\n\
|
|
|
|
\n\
|
|
|
|
A lock is not owned by the thread that locked it; another thread may\n\
|
|
|
|
unlock it. A thread attempting to lock a lock that it has already locked\n\
|
2002-06-13 17:33:02 -03:00
|
|
|
will block until another thread unlocks it. Deadlocks may ensue.");
|
1998-06-27 15:21:06 -03:00
|
|
|
|
2002-08-01 23:27:13 -03:00
|
|
|
PyMODINIT_FUNC
|
2000-07-21 03:00:07 -03:00
|
|
|
initthread(void)
|
1992-08-04 09:41:02 -03:00
|
|
|
{
|
1996-12-16 20:05:22 -04:00
|
|
|
PyObject *m, *d;
|
2005-06-15 09:48:40 -03:00
|
|
|
|
|
|
|
/* Initialize types: */
|
|
|
|
if (PyType_Ready(&localtype) < 0)
|
|
|
|
return;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
|
|
|
/* Create the module and add the functions */
|
1998-06-27 15:21:06 -03:00
|
|
|
m = Py_InitModule3("thread", thread_methods, thread_doc);
|
2006-01-19 02:09:39 -04:00
|
|
|
if (m == NULL)
|
|
|
|
return;
|
1992-08-04 09:41:02 -03:00
|
|
|
|
|
|
|
/* Add a symbolic constant */
|
1996-12-16 20:05:22 -04:00
|
|
|
d = PyModule_GetDict(m);
|
1997-10-01 01:29:29 -03:00
|
|
|
ThreadError = PyErr_NewException("thread.error", NULL, NULL);
|
1996-12-16 20:05:22 -04:00
|
|
|
PyDict_SetItemString(d, "error", ThreadError);
|
1998-06-27 15:21:06 -03:00
|
|
|
Locktype.tp_doc = lock_doc;
|
2009-05-24 20:13:32 -03:00
|
|
|
if (PyType_Ready(&Locktype) < 0)
|
|
|
|
return;
|
1998-06-27 15:21:06 -03:00
|
|
|
Py_INCREF(&Locktype);
|
|
|
|
PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype);
|
1992-08-04 09:41:02 -03:00
|
|
|
|
2005-06-15 09:25:20 -03:00
|
|
|
Py_INCREF(&localtype);
|
2005-06-15 09:48:40 -03:00
|
|
|
if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
|
|
|
|
return;
|
2004-07-14 16:11:50 -03:00
|
|
|
|
2009-10-30 14:07:08 -03:00
|
|
|
nb_threads = 0;
|
|
|
|
|
1992-08-04 09:41:02 -03:00
|
|
|
/* Initialize the C thread library */
|
1998-12-21 15:32:43 -04:00
|
|
|
PyThread_init_thread();
|
1992-08-04 09:41:02 -03:00
|
|
|
}
|