Making termios.tcdrain() work with threads?

Grant Edwards grante at visi.com
Tue Nov 26 15:49:43 EST 2002


In article <as0joa$1jsc$1 at nntp6.u.washington.edu>, Donn Cave wrote:

>| I've noticed that calling termios.tcdrain(fd) (under Unix)
>| blocks all threads instead of just the calling thread.  This is
>| making life a bit difficult for me, so I'm going to take a
>| crack at making it work "right".  Before I try, is there any
>| particular reason why it should behave the way it does now?
> 
> I don't think there could be.  I would guess it's that way
> because someone underestimated the need for it, at least from
> your perspective obviously.

[That's understandible.  These days, few people spend much time
abusing serial ports the way I do...]

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?

-- 
Grant Edwards                   grante             Yow!  My NOSE is NUMB!
                                  at               
                               visi.com            



More information about the Python-list mailing list