Hi,
it seems that threadlocals (instances of python's threading.local()) are not preserved in between calls from Ice runtime to python runtime for the same thread.
Simple example based on printer demo:
To reproduce the bug please run the above script - it should print that it has set up a threadlocal var for two ice threads. Next, please interrupt the script, which will cause ice runtime to call the threadHook.stop() and method shut down the threads that it has started. The threadlocal value set up in threadHook.start() is no longer present when calling threadHook.stop().Code:import sys, traceback, Ice import threading from pprint import pprint, pformat #Ice.loadSlice('Printer.ice') #import Demo #class PrinterI(Demo.Printer): # def printString(self, s, current=None): # print s class ThreadLogger(Ice.ThreadNotification): def __init__(self): super(ThreadLogger, self).__init__() self._tls = threading.local() def start(self): print "ice thread started: " + repr(threading.current_thread()) + " thread locals:" self._tls.my_test_var = "This won't survive until stop()" pprint(self._tls.__dict__) def stop(self): print "ice thread stopped: " + repr(threading.current_thread()) + " thread locals:" pprint(self._tls.__dict__) status = 0 ice = None try: initData = Ice.InitializationData() initData.threadHook = ThreadLogger() ic = Ice.initialize(sys.argv, initData) adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000") #object = PrinterI() #adapter.add(object, ic.stringToIdentity("SimplePrinter")) adapter.activate() ic.waitForShutdown() except: traceback.print_exc() status = 1 if ic: # Clean up try: ic.destroy() except: traceback.print_exec() status = 1 sys.exit(status)
Using threadHook is the simplest and shortest way to demonstrate this behaviour, but is also occurs for example in servant locators - in this case threadlocals are not preserved between calls to locate() and finished().
Tested on win xp 32bit:
- Ice 3.4.1 official binary downloaded from the site
- Python 2.6.6 32-bit official binary
and mac os x 10.6.7:
- Ice 3.4.1 from MacPorts
- Python 2.6.6 from MacPorts

Reply With Quote