odwdinc / Python-SimConnect

Python interface for MSFS2020 SimConnect.dll

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception in Thread-1 when sim is closed

Delilovic opened this issue · comments

Hello! Thank you for the great library!

I have an issue when closing the simulator while connected with SimConnect. The library throws an error in Thread 1 which I can not catch. Doing something like:

try:
    print("Waiting for MSFS_2020 Simulator...")
    sm = SimConnect()
    print("Connected to MSFS_2020!")
except ConnectionError as err:
    print("Error connecting to MSFS2020: {}".format(err))

will not catch the error when connected to the simulator and suddenly closing the simulator. The following exception is thrown and can not be caught, any ideas? Thank you!

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Python\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python\Python39\lib\site-packages\SimConnect\SimConnect.py", line 173, in _run
    self.dll.CallDispatch(self.hSimConnect, self.my_dispatch_proc_rd, None)
  File "_ctypes/callproc.c", line 997, in GetResult
OSError: [WinError -1073741648] Windows Error 0xc00000b0

Hi
Looks like that you have to loop on a condition to check if the simulator is started, it's not done in the small extract you gave.
See https://github.com/odwdinc/Python-SimConnect/blob/master/local_example.py#L69

OSError: [WinError -1073741648] Windows Error 0xc00000b0

Try OSError, lol 🙃

try:
    print("Waiting for MSFS_2020 Simulator...")
    sm = SimConnect()
    print("Connected to MSFS_2020!")
except ConnectionError as err:
    print("Error connecting to MSFS2020: {}".format(err))
except OSError as err:
        print("OS error: {0}".format(err))

Hi
Looks like that you have to loop on a condition to check if the simulator is started, it's not done in the small extract you gave.
See https://github.com/odwdinc/Python-SimConnect/blob/master/local_example.py#L69

@storca

This might be the case if I would send or receive some requests from the simulator which I don't. It is true that I am inside a while loop but not doing anything. Here is a very simple way to reproduce this exception.

  1. Start the sim
  2. Run this python script:
if __name__ == '__main__':
    sm = SimConnect()
    while True:
        sleep(1)

3 Quit the sim
4 Read the exception from the console

@odwdinc it doesn't matter if you put try and except around it, the exception happens inside the thread of SimConnect() that is why you see Thread-1 exception

should be fix in 0.4.24 reopen if not.