Problem: The python server is still alive!
paolo_casarini at libero.it
paolo_casarini at libero.it
Fri Jun 22 08:06:37 EDT 2001
I'm writing an out-of-process COM server using Py2Exe package.
In this server I load an external COM object and I have to handle the
events fired from it.
I testes this server using VB client and all seems work well, but the
problem arises when the client
is closed : THE PYTHON SERVER IS STILL ALIVE and I have to shut-down it
manually with Task-Manager.
The same problem happens also if I use the python local server inside a
C++ client.
In order to check where the problem is I have simplified at maximum the
python code and the the external COM object,
writing the latter using VB and C++, but the problem does not disappear.
Analizing the Python script, the instruction that seems to cause the
problem is
"connection.Connect(server, ConnectableClient
(),IID_IConnectDemoEvents)" :
if I comment it the server process ends correctly when the client
destroies the python COM object.
But, obviously, without this line of code I haven't the possibility to
receive events from my external COM object.
In my opinion it seems that, after the connection, some new objects are
created, but they are not destroyed
when the Disconnect() method is called.
Here follows the minimal python script. I'm using Python 1.5.2
Is there some istruction missing in my code ??
Does my clean-up is not enough ??
Does anyone know how to get around this problem??
Thank you
########################################################################
########
## TechPage.py
import sys
import os
import pythoncom
import win32com.server.util
import win32com.server.connect
import win32com.client.dynamic, win32com.client.connect
import win32com.server.policy
# This is the IID of the Events interface both Client and Server
support.
IID_IConnectDemoEvents = pythoncom.MakeIID("{256FE325-2C6B-4E94-A830-
B758B95FE779}")
# Here is the client side of the connection world.
# Define a COM object which implements the methods defined by the
# IConnectDemoEvents interface.
class ConnectableClient:
_public_methods_ = ["Event1"]
_dispid_to_func_ = { 0x1 : "Event1" }
def _query_interface_(self, iid):
if iid==IID_IConnectDemoEvents: return
win32com.server.util.wrap(self)
# And here is our event method which gets called.
def Pippo( self ):
a = 100 # Nothing importan to do....
if hasattr(sys, 'importers'):
# we are running as py2exe-packed executable
pythoncom.frozen = 1
class PythonUtilities:
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
if hasattr(sys, 'importers'):
# In the py2exe-packed version, specify the module.class
# to use. In the python script version, python is able
# to figure it out itself.
_reg_class_spec_ = "__main__.PythonUtilities"
_public_methods_=['StartServer']
_reg_progid_="PythonDemos.Utilities"
_reg_clsid_="{A63C6B16-05A8-4184-931A-D6A92642D7BF}"
def StartServer( self ):
# I create un instance of my external COM object
# ( a very very simple object written both as ATL
project and VB OCX )
# but the result is the same.....
server = win32com.client.dynamic.Dispatch
("PippoServer.Pippo")
connection = win32com.client.connect.SimpleConnection()
# if I comment this line of code the server will be
correctly discarded
connection.Connect(server, ConnectableClient
(),IID_IConnectDemoEvents)
# a trivial method just to see if the external object
is loaded
server.Metodo1()
# my clean-up:
# is there anything else to do ??
connection.Disconnect()
connection=None
server=None
# Add code so that when this script is run by Python.exe, it self-
registers.
if __name__=='__main__':
if hasattr(sys, 'importers'):
# running as packed executable.
if '--register' in sys.argv[1:] or '--unregister' in
sys.argv[1:]:
# --register and --unregister work as usual
import win32com.server.register
win32com.server.register.UseCommandLine
(PythonUtilities)
else:
# start the server.
from win32com.server import localserver
localserver.main()
else:
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
########################################################################
#########
## Setup.py
## This is the setup script I use to build the executable with py2exe
from distutils.core import setup
import py2exe
setup(name="TechPage", scripts=["TechPage.py"])
------------------------------------------------------------------------
---------
'This is the VB code I use to test the python local server generated
obove
Dim PythonUtils As Object
Private Sub Start_Click()
Set PythonUtils = CreateObject("PythonDemos.Utilities")
response = PythonUtils.StartServer()
End Sub
--
Posted from 195.223.159.86 by way of smtp3.libero.it [193.70.192.53]
via Mailgate.ORG Server - http://www.Mailgate.ORG
More information about the Python-list
mailing list