[PySide] sending data from urllib2.urlopen().read() via signal corrupts in receiver

Frank Rueter | OHUfx frank at ohufx.com
Mon Oct 23 02:38:52 CEST 2017


Great, thank you very much for this!

frank

On 10/23/2017 07:54 AM, Renaud Talon wrote:
>
> Hi Frank !
>
> I first attempted to re-create your issue but I didn’t have any 
> problem on my end. ( using PySide2 + Python3)
>
> That said when I tried the same thing using Python2 I had the same 
> issue as you did. I made a few changes and here is an example I 
> created for you which works for both Python 2 and 3.
>
> https://gitlab.com/talonrenaud/codeSharing/blob/master/urlImgLoader.py
>
> When using Python 3 “urllib.urlopen” returns a “bytes” object which 
> PySide2 has no problem emitting and receiving as such: receivedData = 
> Signal(bytes)
>
> With Python 2 though using “urllib2.urlopen” I can print the image 
> data within the thread and when checking the type it says “str” (which 
> is fine since “str” and “bytes” are the same from what I understand in 
> Py2)
>
> That said after emitting the imgData as a string when I print the 
> imgData type received from the signal it says “Unicode” instead of 
> string and no matter what encoding I set it to (ascii, utf-8, utf-16) 
> I can no longer read/print the imageData.
>
> I am not sure why, this could be a Py2 + PySide2 bug or issue ?
>
> To get around the issue I converted the data to a BytesIO object using 
> the “io” module, setup the signal to use a “BytesIO” type instead of a 
> “str” and that seems to work fine: receivedData = Signal(io.BytesIO)
>
> I am not sure if this is the most elegant way. I’m curious to know 
> what you guys think about this.
>
> Take care,
>
> Renaud
>
> *_______________________________________________*
>
> *Renaud Talon*
>
> Pipeline / TD
>
> *FuseFX*
>
> 14823 Califa Street
>
> Los Angeles, CA 91411
>
> Office:   818-237-5052
>
> Mobile:  310-430-8834
>
> *www.FuseFX.com <http://www.fusefx.com/>*
>
> *From:*PySide 
> [mailto:pyside-bounces+renaudtalon=fusefx.com at qt-project.org] *On 
> Behalf Of *Frank Rueter | OHUfx
> *Sent:* Sunday, October 22, 2017 2:20 AM
> *To:* pyside at qt-project.org
> *Subject:* Re: [PySide] sending data from urllib2.urlopen().read() via 
> signal corrupts in receiver
>
> quick follow up:
> I am now writing the files to a temp directory and only passing the 
> respective path via the signal, but I'm still curious how I would do 
> this without writing anything to disk.
>
> Cheers,
> frank
>
> On 10/22/2017 09:18 PM, Frank Rueter | OHUfx wrote:
>
>     Hi,
>
>     I am downloading a few images in a separate thread using QRunnable.
>     To download I am just using urllib2.urlopen() like this:
>
>     [...]
>         def run(self):
>             imageData = urllib2.urlopen(self.url).read()
>             print 'emitted:', imageData
>             self.signals.receivedData.emit(imageData) # this signal is
>     declared like this: QtCore.Signal(str)
>
>
>     However, the receiving slot is receiving nothing:
>
>         def setPixmap(self, imageData):
>             print 'received:', imageData
>             pixmap = QtGui.QPixmap()
>             pixmap.loadFromData(imageData)
>             self.data['pixmap'] = pixmap
>
>
>     I guess this is too naive an approach to download image data in a
>     separate thread?!
>
>     How can I fix this please?
>
>     Cheers,
>     frank
>
>     -- 
>
>     ohufxLogo 50x50 <http://www.ohufx.com>
>
>     	
>
>     *vfx compositing <http://ohufx.com/index.php/vfx-compositing>**|
>     **workflow customisation and consulting
>     <http://ohufx.com/index.php/vfx-customising> *
>
>
>
>
>     _______________________________________________
>
>     PySide mailing list
>
>     PySide at qt-project.org <mailto:PySide at qt-project.org>
>
>     http://lists.qt-project.org/mailman/listinfo/pyside
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20171023/247d9b3c/attachment.html>


More information about the PySide mailing list