python - 如何将列表和字典传递给线程创建函数
问题描述
在以传统方式创建线程时,我想传递列表和字典对象;怎么做?
例如:
def expectslist(**kwargs):
list=kwargs.values -- not working
def expectsdict(**kwargs):
dictobject=kwargs.values -- not working
def main():
thread1 = Thread(target =expectslist, (args=mylist)) # mylist is list of objects
thread2 = Thread(target =expectsdict, (args=mydict)) # mydict is dictionary of objects (key-objects pair)
解决方案
的值args
是tuple
保存线程函数参数的 a。
例子:
def my_sum(x,y):
return x + y
Thread(target = my_sum,args = (5,9))
推荐阅读
- regex - 仅返回正则表达式模式 kotlin 的一部分
- testing - 具有 SDK 和服务发现支持的持续 E2E 监控
- here-api - HERE API 用于土路导航
- java - Selenium + Java 测试充满了跨度元素。解决不可点击元素问题的最佳方法
- windows - Powershell如何将远程目标与本地目标进行比较以发现差异
- flutter - 什么是 Canvas.save 和 Canvas.restore?
- rest - 加特林测试中的高响应时间
- javascript - 在 Testflight 版本中 React Native 元素的位置错误
- javascript - 反应在单击时访问列表组件的属性
- xamarin - 当我尝试上传微软商店时,UWP / Xamarin 在提交测试中崩溃