New submission from Tim Magee <python...@qkhx.uk>:

Summary: I run a SimpleXMLRPCServer in pythonw. When I call an exposed function 
the call appears to be made twice and the connection ends abnormally.

This is Python 3.8.3 Windows 64-bit, with the pywin32 additions, and under 
Windows 7. Boo, hiss, I know -- I won't have access to a win10 machine for a 
week or so, but I get the impression that that won't affect this behaviour, and 
the post-3.8.3 changelog doesn't have anything that (to me) looks relevant in 
it.

I've made a small reproduction that will run on one Windows machine.
You need two small source files (see below):
  * demosrv.py - the server
  * democli.py - the client
The method, in a CMD window:
  * run: start "demosrv" python demosrv.py
    [ runs in its own console window ]
  * run: python democli.py
    [ one instance of notepad appears and the client exits normally ]
  * Ctrl+C in the demosrv window to stop that
  * run: pythonw demosrv.py
    [ runs in background ]
  * run: python democli.py
    [ TWO notepad instances pop up ]
    [ the client crashes with an unexpected connection ]
I've pasted in the two files and an example session below.

This is very much cut-down from the original.  Before deciding to submit I used 
logging at the top of the exposed function, which appeared to show it being 
called twice.  Logging immediately before the call in the client showed only 
one call.

Thanks,
Tim

#--------------8<---- demosrv.py ----8<------------------------------
from xmlrpc.server import SimpleXMLRPCServer
from subprocess import Popen, DEVNULL

def notepad_me():
    try:
        cmd = ['c:\\windows\\notepad.exe']
        p = Popen(cmd, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
        return True
    except Exception as e:
        return False

class NetServer(SimpleXMLRPCServer):
    def __init__(self, address):
        super(NetServer, self).__init__(address)
        self.register_introspection_functions()
        self.register_function(notepad_me)

with NetServer(("0.0.0.0", 7777)) as server:
    server.serve_forever()

#---------------8<---- democli.py ----8<-----------------------------
import sys
from xmlrpc.client import ServerProxy, Error

def go():
    try:
        with ServerProxy("http://localhost:7777/";) as proxy:
            if proxy.notepad_me():
                return 0
    except Error as e:
        pass
    return 1
sys.exit(go())
#--------------------------------------------------------------------
d:\temp\demo>REM Run the server under python.exe

d:\temp\demo>start "demosrv" python demosrv.py
d:\temp\demo>python democli.py

d:\temp\demo>REM That ran up one instance of notepad
d:\temp\demo>REM Ctrl+C to break out the running demosrv.py

d:\temp\demo>pythonw demosrv.py
d:\temp\demo>REM that runs in the background

d:\temp\demo>python democli.py
Traceback (most recent call last):
  File "democli.py", line 13, in <module>
    sys.exit(go())
  File "democli.py", line 7, in go
    if proxy.notepad_me():
  File "C:\Python\lib\xmlrpc\client.py", line 1109, in __call__
    return self.__send(self.__name, args)
  File "C:\Python\lib\xmlrpc\client.py", line 1450, in __request
    response = self.__transport.request(
  File "C:\Python\lib\xmlrpc\client.py", line 1153, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Python\lib\xmlrpc\client.py", line 1166, in single_request
    resp = http_conn.getresponse()
  File "C:\Python\lib\http\client.py", line 1332, in getresponse
    response.begin()
  File "C:\Python\lib\http\client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:\Python\lib\http\client.py", line 272, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

d:\temp\demo>REM as you see that ran amok
d:\temp\demo>REM and it created two instances of notepad

----------
components: Windows
messages: 387837
nosy: paul.moore, steve.dower, tim.golden, tim_magee, zach.ware
priority: normal
severity: normal
status: open
title: XMLRPC behaves strangely under pythonw, not under python
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to