Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Wie kann ich ein Callback am Programmende oder zwischendurch beenden?

Weil, das Programm scheint den Callback noch abarbeiten zu wollen, obwohl das Programm beendet und somit auch (ordnungsgemäß) ipcon.destroy() ausgeführt worden ist.

 

Exception in thread Thread-2:

Traceback (most recent call last):

  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner

    self.run()

  File "/usr/lib/python2.7/threading.py", line 504, in run

    self.__target(*self.__args, **self.__kwargs)

  File "/home/jan/python/tinkerforge/ip_connection.py", line 227, in callback_loop

    device.registered_callbacks[function_id](*self.data_to_return(data[4:], form))

  File "test_servo_callback.py", line 27, in cb_reached

    distanz1=dist1.get_distance()

  File "/home/jan/python/tinkerforge/ip_connection.py", line 76, in func

    return f(self, *args, **kwargs)

  File "/home/jan/python/tinkerforge/bricklet_distance_ir.py", line 70, in get_distance

    return self.ipcon.send_request(self, DistanceIR.FUNCTION_GET_DISTANCE, (), '', 'H')

  File "/home/jan/python/tinkerforge/ip_connection.py", line 306, in send_request

    raise Error(Error.TIMEOUT, msg)

Error: -1: Did not receive response for function 1 in time

Geschrieben

Du hast da eine Race Condition entdeckt. Ich denke es passiert da folgendes:

 

Du rufst destroy() auf, der Socket wird geschlossen und der Receive Thread wird beendet. Der Callback Thread läuft aber noch weil noch was in der Callback Queue ist. Daher führt er den Callback noch aus. Im Callback rufst du get_distance() auf. Das bekommt einen Timeout weil der Receive Thread nicht mehr läuft und keine Antwort mehr ankommt.

 

Damit das richtig funktioniert muss in destroy() zuerst den Callback Thread beenden werden und erst wenn der keine Callbacks mehr bearbeitet, dann erst kann der Receive Thread beendet.

 

Ich hab das in der angehängten ip_connection.py so abgeändert, damit sollte das Problem nicht mehr auftreten. Kannst du das testen?

ip_connection.py

Geschrieben

Ist das ein Unterschied zu den C#-Bindings oder habe ich das falsch im Kopf?

Ich würde denken in den C#-Bindings geht der Callback-Thread sofort fort, kann mich aber auch täuschen.

Geschrieben
  • Autor

Werd ich am Wochenende testen. Danke.

Geschrieben
  • Autor

Danke, das ist super.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.