HI Mark and Hi all,
as I wrote previously Mark's solution did not work for me. I need
pythonsevice.exe is able to pass -X utf8 parameter to python interpreter or
in alternative is able to evaluate evaluate the environment
variable PYTHONUTF8=1. Any suggestions?
Please help me.
Thanks in advance


Il giorno lun 5 giu 2023 alle ore 10:51 Gualtiero Scotti <tie...@gmail.com>
ha scritto:

> HI Mark,
> I've tried your solution but it doesn't work. When calling python
> directly, service fails to start.
> When i use
> #_exe_name_ = sys.executable
> #_exe_args_ = ' -X utf8 ' + '"' + os.path.abspath(sys.argv[0]) + '"'
> service are directly linked to my python app without using
> pythonservice.exe. ( I saw this on Regedit)
>
> *As you wrote on your example:*
>
>
> # This is an example of a service hosted by python.exe rather than
> # pythonservice.exe.
>
> # *Note that it is very rare that using python.exe is a better option*
> # than the default pythonservice.exe - the latter has better error handling
> # so that if Python itself can't be initialized or there are very early
> # i*mport errors, you will get error details written to the event log*.
> When
> # using python.exe instead, you are forced to wait for the interpreter
> startup
> # and imports to succeed before you are able to effectively setup your own
> # error handling.
>
>
> *# So in short, please make sure you *really* want to do this, otherwise
> just# stick with the default.*
>
>  I need to use pythonservice.exe but I don't understand how it wraps my
> python application. Is there a way to tell to pythonservice.exe to call
> python with some interpreter arguments?
> Thanks in advance.
>
>
> Il giorno gio 1 giu 2023 alle ore 17:05 Mark Hammond <
> skippy.hamm...@gmail.com> ha scritto:
>
>>
>> https://github.com/mhammond/pywin32/blob/main/win32/Demos/service/nativePipeTestService.py
>> is a demo of using a service using python.exe and supports specifying the
>> command-line, so that might be an option?
>>
>> Mark
>> On 2023-06-01 5:28 a.m., Gualtiero Scotti wrote:
>>
>> Hi, I need to start my python application through windows service. For
>> this purpose I use pywin32.
>> I'm not able to make a Python instance to evaluate the -X uf8 flag.
>>
>> This flag must be passed during python invocation only and not when it is
>> already started.
>> After some investigations I've found the service launch
>> *pythonservice.exe* wrapper but I don't know how to pass the flag to the
>> Python interpreter.
>>
>> Is there another option to set this flag? It is possible to set an env
>> variable *PYTHONUTF8=1 * but pythonservice.exe doesn't seem to evaluate
>> it...
>>
>> *My environment*
>> *- Windows 11 Home 22H2*
>> *- Python 3.11.1* (tags/v3.11.1:a7a450f, Dec  6 2022, 19:43:28) [MSC
>> v.1934 32 bit (Intel)] on win32
>> - *Pywin32 305*
>> - *Pywin32-ctypes 0.2.0*
>>
>> *Python documentation*
>> 4.7. UTF-8 mode¶
>> <https://docs.python.org/3/using/windows.html#utf-8-mode>
>>
>> New in version 3.7.
>>
>> Windows still uses legacy encodings for the system encoding (the ANSI
>> Code Page). Python uses it for the default encoding of text files (e.g.
>> locale.getencoding()
>> <https://docs.python.org/3/library/locale.html#locale.getencoding>).
>>
>> This may cause issues because UTF-8 is widely used on the internet and
>> most Unix systems, including WSL (Windows Subsystem for Linux).
>>
>> You can use the Python UTF-8 Mode
>> <https://docs.python.org/3/library/os.html#utf8-mode> to change the
>> default text encoding to UTF-8. You can enable the Python UTF-8 Mode
>> <https://docs.python.org/3/library/os.html#utf8-mode> via the -X utf8 command
>> line option, or the PYTHONUTF8=1 environment variable. See PYTHONUTF8
>> <https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUTF8> for
>> enabling UTF-8 mode, and Excursus: Setting environment variables
>> <https://docs.python.org/3/using/windows.html#setting-envvars> for how
>> to modify environment variables.
>>
>> When the Python UTF-8 Mode
>> <https://docs.python.org/3/library/os.html#utf8-mode> is enabled, you
>> can still use the system encoding (the ANSI Code Page) via the “mbcs” codec.
>>
>> Note that adding PYTHONUTF8=1 to the default environment variables will
>> affect all Python 3.7+ applications on your system. If you have any Python
>> 3.7+ applications which rely on the legacy system encoding, it is
>> recommended to set the environment variable temporarily or use the -X
>> utf8 command line option.
>>
>> Note
>>
>>
>> Even when UTF-8 mode is disabled, Python uses UTF-8 by default on Windows
>> for:
>>
>>    -
>>
>>    Console I/O including standard I/O (see *PEP 528*
>>    <https://peps.python.org/pep-0528/> for details).
>>    -
>>
>>    The filesystem encoding
>>    
>> <https://docs.python.org/3/glossary.html#term-filesystem-encoding-and-error-handler>
>>     (see *PEP 529* <https://peps.python.org/pep-0529/> for details).
>>
>> from -> https://docs.python.org/3/using/windows.html
>>
>> Please help me!
>> Thanks in advance
>>
>>
>> _______________________________________________
>> python-win32 mailing 
>> listpython-win32@python.orghttps://mail.python.org/mailman/listinfo/python-win32
>>
>>
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to