Ticket #13490 (confirmed Bug)

Opened 3 years ago

Last modified 3 years ago

Unfortunate "sys.argv" for "bin/<instance> run"

Reported by: dieter Owned by:
Priority: minor Milestone: 4.x
Component: Backend (Python) Version: 4.2
Keywords: Cc: dieter@…

Description

When a (normal) Python script is run, Python sets "sys.argv" to "<script> <arg> ...". This was also the value of "sys.argv" for scripts started with "bin/instance run" at least until Plone 3. In Plone 4.2.4, I now observe that "sys.argv" is ".../bin/<instance> -c <script> <arg> ..." in this case. This value is unfortunate as it neither represents the typical Python behaviour (it would have "run" instead of "-c") nor the most natural value from the script point of view (which was the one used until Plone 3).

The new behaviour requires adaptation of all scripts with parameters to be started by "bin/<instance> run" and it is difficult to do this generically by looking at "sys.argv[1]" (as "-c" may be a script option) for scripts which are used both in a Plone 3 as well as a Plone 4.2.4 environment.

Change History

comment:1 Changed 3 years ago by kleist

  • Status changed from new to confirmed
  • Component changed from Unknown to Backend (Python)

comment:2 Changed 3 years ago by dieter

  • Cc dueter@… added

comment:3 Changed 3 years ago by dieter

  • Cc dieter@… added; dueter@… removed

comment:4 Changed 3 years ago by dieter

The behaviour comes from plone.recipe.zope2instance==4.2.8, the do_run function. Its comment says, it wants the old behaviour with "<script> <arg> ..." as content of "sys.argv" but it uses unreliable code to achieve this (and gets it wrong). I suggest to replace "sys.argv.pop()" there by "del sys.argv[:]". This ensures that "<script>" becomes "argv[0]" (independent of what "sys.argv" may happen to have as value).

Zope 2.13, too, uses "<script> <arg> ..." as value of "sys.argv" in "bin/zopectl run <script> <arg> ...". This might be an additional indication that the old (Plone 3) behaviour should be restored (rather than switching to Python "sys.argv" setting).

Note: See TracTickets for help on using tickets.