multithreading - Error in Sending a mp3 files using Python -


i trying send mp3 files through python. here following code -

for v in videos:      thread(target=video_download, args=(handler,v,videos)).start()   def video_download(handler,v,videos):       try:         ydl_opts['format'] = 'mp4'         ydl(ydl_opts).download([v])     except:         ydl_opts['format'] = 'best'         ydl(ydl_opts).download([v])          mp3  = open('./'+v+'.mp3', "r+").read()     handler.send_header('content-disposition', 'attachment; filename=%s.mp3' % videos[v])     handler.wfile.write(mp3)     handler.end_headers() 

it downloads m4a format video youtube , converts mp3 files. download , conversion part working perfectly, uses threading, while sending file using wfile.write() receive following error

traceback (most recent call last):   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner     self.run()   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/threading.py", line 763, in run     self.__target(*self.__args, **self.__kwargs)   file "/users/keshav/documents/github/webserver/webserver/downld.py", line 37, in video_download     handler.send_header('content-disposition', 'attachment; filename=%s.mp3' % videos[v])   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/basehttpserver.py", line 401, in send_header     self.wfile.write("%s: %s\r\n" % (keyword, value))   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/socket.py", line 324, in write     self.flush()   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/socket.py", line 303, in flush     self._sock.sendall(view[write_offset:write_offset+buffer_size]) attributeerror: 'nonetype' object has no attribute 'sendall' 

the same thing works fine if implement multiprocessing instead of threading. processing serially instead of parallel.


Comments

Popular posts from this blog

Hard vs. Soft Water: What's The Difference?

What Are The Best Universities In The World?

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -