I am running the following python line of code within a small windows service application which is multiprocessed.
multiprocessing.Manager()
The issue is there appears to be no attribute argv within the module sys set when running a windows service. As a result of this I get the following error occur within the python multiprocessing forking library. I was hoping someone might be able to shed some light on this issue.
Stacktrace of issue (when running multiprocessing.Manager within windows service):
File "C:\python27\lib\multiprocessing\__init__.py", line 99, in Manager
m.start()
File "C:\python27\lib\multiprocessing\managers.py", line 524, in start
self._process.start()
File "C:\python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "C:\python27\lib\multiprocessing\forking.py", line 252, in __init__
cmd = get_command_line() + [rhandle]
File "C:\python27\lib\multiprocessing\forking.py", line 339, in get_command_line
if process.current_process()._identity==() and is_forking(sys.argv):
AttributeError: 'module' object has no attribute 'argv
Update
One possible solution to my problem is that I manually set the sys.argv
value if it is not set at runtime but this seems very unpythonic. But might be the only solution. What do stackoverflow-ers think?
if not hastattr(sys, 'argv'):
sys.argv = []
But, this then leads me to a new issue with the multiprocessing.manager where by an unexpected EOFError occurs within the code.
File "C:\python27\lib\multiprocessing\__init__.py", line 99, in Manager
m.start()
File "C:\python27\lib\multiprocessing\managers.py", line 528, in start
self._address = reader.recv()
EOFError
Since setting sys.argv = []
didn't work, if there is a script name you might be able to use do sys.argv = ['scriptname']
or just sys.argv = ['']
. The latter is what you get if you run python, import sys
and then look at sys.argv
, eg,
~$ python
>>> import sys
>>> sys.argv
['']
Call this function after Python initialization:
PySys_SetArgv(argc, argv);
The interpreter can't get access to argc/argv in other way rather then passing them explicitly from main().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.