跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

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.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 请教一个 Python 中线程共享数据的问题

发表于

我想在 main 和它建立的线程间共享数据,在线程中执行逻辑,更新数据,主线程中读取判断。

  1. 由于数据较多,使用 dataclass 当 struct 用
  2. 线程中写,main 中只读,所有没有加锁 实际使用发现,这个数据共享不是完全引用,变量地址(使用 id 查看两边地址)会有改变,导致 main 和 thread 中的变量不是一个东西了,监测失败。
  3. tricky 的是,第一次创建的线程没有问题。跑完一次,第二次再来一次就大概率出问题,后续再尝试就一直会出问题了,偶尔会成功。 请问如果要实现多线程共享数据的读写,有什么最佳实现和模板吗

Featured Replies

No posts to show

创建帐户或登录来提出意见

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.