Python Forum
Problems with variables in multithreading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with variables in multithreading
#1
Question 
I have a problem and have no idea how to solve it. So I have n-threads to download data via bluetooth. This data has to go through a handler which unfortunately runs in a new thread of its own, the handler makes its call in C++ to an API. In this handler I want to count up an index. I'm currently trying with threading.local, but that doesn't work because of the new thread that is automatically created. Can anyone help me?

def data_downloader(...):
   points = threading.local()
   point.x = 0
   t = np.zeros((n))
   data = np.zeros((n, 3))

   def handler(p):
        t[point.x] = p.contents.epoch
        data[point.x] = parse_value(p)  
        point.x += 1  # unfortunately, they don't add up here

    callback = FnVoid_VoidP_DataP(lambda ctx, p: handler(p))  # casts the handler to a c++ handler

    get_data(..., callback)  # the data is downloaded here, afterwards the data is processed by the handler
edit: Python version is 3.7
Reply
#2
see: https://stackoverflow.com/a/19034408
Reply
#3
(Mar-07-2022, 09:24 PM)Larz60+ Wrote: see: https://stackoverflow.com/a/19034408
Thanks for the help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  multithreading Hanyx 4 1,319 Jul-29-2022, 07:28 AM
Last Post: Larz60+
  Multithreading question amadeok 0 1,773 Oct-17-2020, 12:54 PM
Last Post: amadeok
  How can i add multithreading in this example WoodyWoodpecker1 3 2,506 Aug-11-2020, 05:30 PM
Last Post: deanhystad
  matplotlib multithreading catosp 0 2,944 Jul-03-2020, 09:33 AM
Last Post: catosp
  Multithreading dynamically syncronism Rodrigo 0 1,529 Nov-08-2019, 02:33 AM
Last Post: Rodrigo
  Locks in Multithreading Chuonon 0 1,839 Oct-03-2019, 04:16 PM
Last Post: Chuonon
  multithreading issue with output mr_byte31 4 3,195 Sep-11-2019, 12:04 PM
Last Post: stullis
  Multithreading alternative MartinV279 1 2,778 Aug-01-2019, 11:41 PM
Last Post: scidam
  using locks in multithreading in python3 srm 2 3,667 Jul-13-2019, 11:35 AM
Last Post: noisefloor
  problems with the If statement or is it the variables being used NickIgoe 2 2,132 Mar-22-2019, 06:34 AM
Last Post: NickIgoe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020