[Python-Dev] How should I handle unsupported features?

"Martin v. Löwis" martin at v.loewis.de
Sun Jan 11 18:53:13 CET 2009


> Porting to MS Windows CE, I find that e.g. signals or environment vars are not 
> supported. How should I handle that? 

So that scripts that try to make use of these features operate in a
reasonable way.

> In particular, I'm talking about 
> PyOS_getsig() and PyOS_setsig(). Should I just #ifdef them out completely or 
> should I implement them by setting an error? Which error should I set?

My proposal would be to actually implement signal handlers for CE. Try
to minimize the amount of code change that you need to perform (*). Not
sure what exactly that means, but probably, you need to provide at least
the symbolic constants mandated by C.

E.g. define NSIG, SIG_IGN, SIG_DFL, SIGINT, and perhaps a few others
the same way the the VS9 CRT defines them, then implement PyOS_setsig
so that it operates on an array of NSIG function pointers. None of
the signal handlers will ever be called - which essentially means that
the signals just don't arise. Alternatively, if you regret the storage
for the signal handlers, you might
a) make some or all of the signals not supported; signal(2) is defined
   to return SIG_ERR in that case, and set errno to EINVAL. Not sure
   what will break if Python can't even successfully set a SIGINT
   handler.
b) cheat on setsig, not actually recording the signal handler. Not sure
   whether any code relies on getsig(k, setsig(k, f)) == f

Regards,
Martin

(*) This is a general advise. If some feature is not supported on a
minority platform, it would be a pity if a lot of code needs to be
written to work around.


More information about the Python-Dev mailing list