cinap_lenrekadd hg and python4bb9e2215 years agoHistory
720 lines · 18.5 KB · C
RawDownload
PyDoc_STRVAR(start_new_doc,"start_new_thread(function, args[, kwargs])\n\(start_new() is an obsolete synonym)\n\\n\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\printed unless the exception is SystemExit.\n"); static PyObject *thread_PyThread_exit_thread(PyObject *self){	PyErr_SetNone(PyExc_SystemExit);	return NULL;} PyDoc_STRVAR(exit_doc,"exit()\n\(PyThread_exit_thread() is an obsolete synonym)\n\\n\This is synonymous to ``raise SystemExit''.  It will cause the current\n\thread to exit silently unless the exception is caught."); static PyObject *thread_PyThread_interrupt_main(PyObject * self){	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\A subthread can use this function to interrupt the main thread."); #ifndef NO_EXIT_PROGstatic PyObject *thread_PyThread_exit_prog(PyObject *self, PyObject *args){	int sts;	if (!PyArg_ParseTuple(args, "i:exit_prog", &sts))		return NULL;	Py_Exit(sts); /* Calls PyThread_exit_prog(sts) or _PyThread_exit_prog(sts) */	for (;;) { } /* Should not be reached */}#endif static lockobject *newlockobject(void); static PyObject *thread_PyThread_allocate_lock(PyObject *self){	return (PyObject *) newlockobject();} PyDoc_STRVAR(allocate_doc,"allocate_lock() -> lock object\n\(allocate() is an obsolete synonym)\n\\n\Create a new lock object.  See LockType.__doc__ for information about locks."); static PyObject *thread_get_ident(PyObject *self){	long ident;	ident = PyThread_get_thread_ident();	if (ident == -1) {		PyErr_SetString(ThreadError, "no current thread ident");		return NULL;	}	return PyInt_FromLong(ident);} PyDoc_STRVAR(get_ident_doc,"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\A thread's identity may be reused for another thread after it exits."); 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)."); static PyMethodDef thread_methods[] = {	{"start_new_thread",	(PyCFunction)thread_PyThread_start_new_thread,	                        METH_VARARGS,				start_new_doc},	{"start_new",		(PyCFunction)thread_PyThread_start_new_thread, 	                        METH_VARARGS,				start_new_doc},	{"allocate_lock",	(PyCFunction)thread_PyThread_allocate_lock, 	 METH_NOARGS, allocate_doc},	{"allocate",		(PyCFunction)thread_PyThread_allocate_lock, 	 METH_NOARGS, allocate_doc},	{"exit_thread",		(PyCFunction)thread_PyThread_exit_thread, 	 METH_NOARGS, exit_doc},	{"exit",		(PyCFunction)thread_PyThread_exit_thread, 	 METH_NOARGS, exit_doc},	{"interrupt_main",	(PyCFunction)thread_PyThread_interrupt_main,	 METH_NOARGS, interrupt_doc},	{"get_ident",		(PyCFunction)thread_get_ident, 	 METH_NOARGS, get_ident_doc},	{"stack_size",		(PyCFunction)thread_stack_size,				METH_VARARGS,				stack_size_doc},#ifndef NO_EXIT_PROG	{"exit_prog",		(PyCFunction)thread_PyThread_exit_prog,	 METH_VARARGS},#endif	{NULL,			NULL}		/* sentinel */};  /* Initialization function */ PyDoc_STRVAR(thread_doc,"This module provides primitive operations to write multi-threaded programs.\n\The 'threading' module provides a more convenient interface."); PyDoc_STRVAR(lock_doc,"A lock object is a synchronization primitive.  To create a lock,\n\call the PyThread_allocate_lock() function.  Methods are:\n\\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\will block until another thread unlocks it.  Deadlocks may ensue."); PyMODINIT_FUNCinitthread(void){	PyObject *m, *d;		/* Initialize types: */	if (PyType_Ready(&localtype) < 0)		return; 	/* Create the module and add the functions */	m = Py_InitModule3("thread", thread_methods, thread_doc);	if (m == NULL)		return; 	/* Add a symbolic constant */	d = PyModule_GetDict(m);	ThreadError = PyErr_NewException("thread.error", NULL, NULL);	PyDict_SetItemString(d, "error", ThreadError);	Locktype.tp_doc = lock_doc;	Py_INCREF(&Locktype);	PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); 	Py_INCREF(&localtype);	if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)		return; 	/* Initialize the C thread library */	PyThread_init_thread();}

Lines 501–720 of 720. Previous lines