Here is my logic that I am trying to understand.
import xlwings as xw
import threading
workbook = ""
def function1():
t1 = threading.Thread(target=function2)
t1.start()
t1.join()
def function2():
global workbook
workbook = xw.Book()
function1()
print (workbook)
When I run the following I am receiving the following message:
Traceback (most recent call last):
File "c:\Users\rakesh.ramanjulu\Documents\Python Projects\Vendor ScoreCard Accuracy Final\test.py", line 51, in <module>
print (workbook)
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\xlwings\main.py", line 1288, in __repr__
return "<Book [{0}]>".format(self.name)
^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\xlwings\main.py", line 1105, in name
return self.impl.name
^^^^^^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\xlwings\_xlwindows.py", line 837, in name
return self.xl.Name
^^^^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\xlwings\_xlwindows.py", line 199, in __getattr__
v = getattr(self._inner, item)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\xlwings\_win32patch.py", line 55, in __getattr__
return getattr(d, attr)
^^^^^^^^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\win32com\client\__init__.py", line 585, in __getattr__
return self._ApplyTypes_(*args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rakesh.ramanjulu\AppData\Local\Programs\Python\Python312\Lib\site-packages\win32com\client\__init__.py", line 574, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147220995, 'Object is not connected to server', None, None)
I am slightly confused as to why this is happening. Updating a global variable via threads has never caused me issues, but not sure hot to address the above situation. I would assume that the variable would change, but nope.