Making termios.tcdrain() work with threads?
Donn Cave
donn at u.washington.edu
Tue Nov 26 18:20:25 EST 2002
Quoth grante at visi.com (Grant Edwards):
...
| OK, the change is simple enough:
|
| Py_BEGIN_ALLOW_THREADS
| s = tcdrain(fd);
| Py_END_ALLOW_THREADS
| if (s == -1)
| return PyErr_SetFromErrno(TermiosError);
|
|
| [similar thing done in the other 5 methods]
|
| It works just peachy now.
|
| But, before I submit a patch, I've noticed that TermiosError is
| a single, static object (file scope):
|
| static PyObject *TermiosError;
|
| Is this going to cause problems if multiple threads have to
| return errors from the termios methods?
Don't think so!
PyEND_ALLOW_THREADS waits for the interpreter lock, so there's only
one thread at a time past that point. PyErr_SetFromErrno should tuck
that data into the thread specific state before control gets to the
ceval loop where another thread could take over. And I wouldn't think
you'd be modifying TermiosError anyway.
As long as 's' is automatic (stack/register) storage, you're fine.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list