Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性错误:';模块';对象没有属性'_strtime';(在Python2.7中使用threading.Thread的threading time.strtime)_Python_Multithreading_Python 2.7_Time - Fatal编程技术网

属性错误:';模块';对象没有属性'_strtime';(在Python2.7中使用threading.Thread的threading time.strtime)

属性错误:';模块';对象没有属性'_strtime';(在Python2.7中使用threading.Thread的threading time.strtime),python,multithreading,python-2.7,time,Python,Multithreading,Python 2.7,Time,我想知道是否有人曾经面对过这个问题,并且有一个解决方案 回溯主要错误:AttributeError:“模块”对象没有属性“\u strTime” 在Python2.7中的线程中运行time.strtime时 与本期类似: 回溯 2.7.8 |Continuum Analytics, Inc.| (default, Aug 21 2014, 18:22:21) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] 2018-07-31 17:18:07,888 INFO

我想知道是否有人曾经面对过这个问题,并且有一个解决方案

回溯主要错误:AttributeError:“模块”对象没有属性“\u strTime”

在Python2.7中的线程中运行time.strtime时 与本期类似:

回溯

2.7.8 |Continuum Analytics, Inc.| (default, Aug 21 2014, 18:22:21) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
2018-07-31 17:18:07,888 INFO __main__ 21304/139920311363328: Starting script for # of jobs: 2 running # of workers at a time 2...
2018-07-31 17:18:07,888 DEBUG __main__ 21304/139920311363328: Starting run_tasks_concurrently 2 tasks with pool_size 2
2018-07-31 17:18:07,889 DEBUG __main__ 21304/139920173688576: Thread: <Thread(Thread-1, started daemon 139920173688576)> is running: <function a_worker_fnc at 0x7f41b440f140> with kwargs: {'x': 0}
2018-07-31 17:18:07,890 DEBUG __main__ 21304/139920161081088: Thread: <Thread(Thread-2, started daemon 139920161081088)> is running: <function a_worker_fnc at 0x7f41b440f140> with kwargs: {'x': 1}
2018-07-31 17:18:07,890 DEBUG __main__ 21304/139920311363328: Waiting for tasks 0->2 to finish out of total 2 tasks
2018-07-31 17:18:07,890 ERROR __main__ 21304/139920161081088: run_tasks_concurrently._worker unhandled Exception: 'module' object has no attribute '_strptime_time'
Traceback (most recent call last):
  File "/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py", line 34, in _worker_process_queue
    task_output = worker_fnc(**task_input)
  File "/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py", line 152, in a_worker_fnc
    time.strptime('Tue, 31 Jul 2018 17:15:24 GMT', '%a, %d %b %Y %X GMT')
AttributeError: 'module' object has no attribute '_strptime_time'
Traceback (most recent call last):
  File "/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py", line 168, in <module>
    main()
  File "/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py", line 164, in main
    print(run_tasks_concurrently(no_of_workers, a_worker_fnc, tasks))
  File "/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py", line 123, in run_tasks_concurrently
    raise RuntimeError("Unhandled exceptions caught in threads:\n{}".format(error_msgs))
RuntimeError: Unhandled exceptions caught in threads:
For give task input {'x': 1} unhandled exception 'module' object has no attribute '_strptime_time'
2.7.8 | Continuum Analytics,Inc.|(默认,2014年8月21日,18:22:21)
[GCC 4.4.7 20120313(Red Hat 4.4.7-1)]
2018-07-31 17:18:07888信息主站21304/13992031133328:作业开始脚本:一次运行两个工人2。。。
2018-07-31 17:18:07888调试主站21304/13992031311363328:启动运行任务同时运行两个任务,池大小为2
2018-07-31 17:18:07889调试uuu main_uuuuuuuu21304/139920173688576:线程:正在运行:带kwargs:{'x':0}
2018-07-31 17:18:07890调试main\uuuuuuuu21304/139920161088:线程:正在运行:带kwargs:{'x':1}
2018-07-31 17:18:07890调试主站21304/13992031133328:等待任务0->2完成总共2个任务
2018-07-31 17:18:07890错误\uuuuuuuuuuu main\uuuuuuuuuu21304/139920161088:同时运行\u任务。\u工作人员未处理的异常:“模块”对象没有属性“\u strptime\u time”
回溯(最近一次呼叫最后一次):
文件“/home/barikak/workspace/py27sandbox/concurrency\u vs\u threading\u vs\u multiprocessing/threading\u example.py”,第34行,在工作进程队列中
任务输出=工人fnc(**任务输入)
文件“/home/barikak/workspace/py27sandbox/concurrency\u vs\u threading\u vs\u multiprocessing/threading\u example.py”,第152行,在一个工作线程fnc中
time.strtime('2018年7月31日星期二17:15:24 GMT','%a,%d%b%Y%X GMT')
AttributeError:“模块”对象没有属性“\u strtime\u time”
回溯(最近一次呼叫最后一次):
文件“/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py”,第168行,在
main()
文件“/home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py”,第164行,在main中
打印(同时运行任务(无工作人员、工作人员、任务))
文件“/home/barikak/workspace/py27sandbox/concurrency\u vs\u threading\u vs\u multiprocessing/threading\u example.py”,第123行,同时运行任务
raise RUNTIMERROR(“线程中捕获的未处理异常:\n{}”。格式(错误\u msgs))
RuntimeError:线程中捕获到未处理的异常:
对于给定任务输入{'x':1}未处理的异常“module”对象没有属性“\u strptime\u time”
在Python3.4过程中相同

(pyenv34) barikak@dev-dsk:~% python /home/barikak/workspace/py27sandbox/concurrency_vs_threading_vs_multiprocessing/threading_example.py
3.4.0 |Continuum Analytics, Inc.| (default, Mar 17 2014, 16:13:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
2018-07-31 17:22:41,863 INFO __main__ 22009/140545970165504: Starting script for # of jobs: 2 running # of workers at a time 2...
2018-07-31 17:22:41,863 DEBUG __main__ 22009/140545970165504: Starting run_tasks_concurrently 2 tasks with pool_size 2
2018-07-31 17:22:41,863 DEBUG __main__ 22009/140545839482624: Thread: <Thread(Thread-1, started daemon 140545839482624)> is running: <function a_worker_fnc at 0x7fd360d8c6a8> with kwargs: {'x': 0}
2018-07-31 17:22:41,864 DEBUG __main__ 22009/140545758328576: Thread: <Thread(Thread-2, started daemon 140545758328576)> is running: <function a_worker_fnc at 0x7fd360d8c6a8> with kwargs: {'x': 1}
2018-07-31 17:22:41,864 DEBUG __main__ 22009/140545970165504: Waiting for tasks 0->2 to finish out of total 2 tasks
2018-07-31 17:22:41,869 DEBUG __main__ 22009/140545970165504: runtime for run_tasks_concurrently: 0:00:00.005774 result length: 2
[0, 1]
0:00:00.006079
(pyenv34) barikak@dev-dsk:~%
(pyenv34)barikak@dev-dsk:~%python/home/barikk/workspace/py27sandbox/concurrency\u vs\u threading\u vs\u multiprocessing/threading\u example.py
3.4.0 | Continuum Analytics,Inc.|(默认,2014年3月17日,16:13:14)
[GCC 4.1.2 20080704(Red Hat 4.1.2-54)]
2018-07-31 17:22:41863信息-主要内容22009/140545970165504:作业开始脚本:一次运行两个工人2。。。
2018-07-31 17:22:41863调试主要任务22009/140545970165504:同时启动运行任务2个任务,池大小为2
2018-07-31 17:22:41863调试主线程22009/140545839482624:线程:正在运行:带kwargs:{'x':0}
2018-07-31 17:22:41864调试主线程22009/140545758328576:线程:正在运行:带kwargs:{'x':1}
2018-07-31 17:22:41864调试(主控)22009/140545970165504:等待任务0->2完成总共2个任务
2018-07-31 17:22:41869调试主站22009/140545970165504:并发运行任务的运行时:0:00:00.005774结果长度:2
[0, 1]
0:00:00.006079
(第34页)barikak@dev-dsk:~%
解决方案是按照前面描述的方法进行操作

import _strptime
from datetime import datetime

# then, in threaded block
datetime.strptime(date, format)

错误表明您试图使用
\u strtime\u time
,而不是
\u strtime
。也许这就是你的问题?找到了解决方案:可能重复
import _strptime
from datetime import datetime

# then, in threaded block
datetime.strptime(date, format)