[PATCH] sys.modify_argv()

Dave Cinege dcinege at psychosis.com
Fri Aug 24 23:53:04 EDT 2001


Ignacio Vazquez-Abrams wrote:
> 
> On Fri, 24 Aug 2001, Dave Cinege wrote:
> 
> > keywords: modify argv change process listing argv[0] ps output
> >
> > This patch adds a new feature to the sys module, modify_argv().
> > As you might have guessed this allows one to change to absolute
> > argv values of the python process itself. (It is of great wonder
> > to me why this functionality is not already available...)
> 
> Instead of making a whole new function for this, why not add write capability
> to sys.argv?

Why I didn't do this:

1) From what I've looked at, the current sys code would change
dramatically as it's already dealing in copies of argv initialized
at python startup, and not by accessing  Py_GetArgcArgv() dynamically.
What I did is less intrusive and portable outside of sys.

2) Even though one clears the absolute argv, you probably still want
it's values available internally. Thus clearing the sys.argv copies
adds a layer of complexity that is really unneeded and probably undesirable.

3) It's not yet exactly clear (to me) to what extent you can alter argv
and not impeed portability. This is probably reason enough to segregate this
functionality. (On linux it stacks argv elements concurrently in memory and
it's safe to use that total space anyway you want. Who knows
how other OS's deal with it...)

4) sys.argv[0] == argv[1]. How do we get to the real argv[0] in a
sane way? sys.argv[-1] Might break old code as the current implementation
ignores negatives and uses absolute values. Also making process
listing follow sys.agrv assignment might break old code. And then
we have to deal with the lengths of the orginial argv elements again...


This is the first time I've ever even looked at the python source,
and am hardly close to being a python guru myself. There might be
a better solution then what I've done, though I've tried to put a bit
of thought into it. At least this patch is usable by people
now and will hopefully lead to SOME sort of standard argv modification
support in the near future.

Dave




More information about the Python-list mailing list