write_async inserting garbage (with Python through introspection)
@pbattiston
Submitted by Pietro Battiston Link to original bug (#667397)
Description
Let me first clarify that I'm unable to understand if this is a glib, glib introspection or Python introspection support problem.
That said: when you run the following Python code:
----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----
#! /usr/bin/python
from gi.repository import Gio, GLib
class Writer(object): def write(self): self.g = Gio.file_new_for_uri( 'file:///tmp/stupid' ) self.stream = self.g.create( 0, None ) self.stream.write( "hello\n", None ) self.stream.close( None ) self.loop.quit()
u = Writer() GLib.timeout_add(10, u.write) u.loop = GLib.MainLoop() u.loop.run()
----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----
you correctly find a "/tmp/stupid" file saying "Hello". If you do the same with an async write:
----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----
#! /usr/bin/python
from gi.repository import Gio, GLib
class Writer(object): def write(self): self.g = Gio.file_new_for_uri( 'file:///tmp/stupid' ) self.stream = self.g.create( 0, None ) self.stream.write_async( "hello\n", GLib.PRIORITY_DEFAULT, None, self.written, None )
def written(self, gdaemonfile, result, data):
print self.stream.write_finish( result )
self.stream.close( None )
self.loop.quit()
u = Writer() GLib.timeout_add(10, u.write) u.loop = GLib.MainLoop() u.loop.run()
----8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<----
instead it won't work: the file will probably be empty. If then you replace "hello\n" with "hello\n"*10 you will find a non-empy file, and some iterations of "hello\n", but also some garbage (which changes from time to time).
I'm running under Debian with: libglib2.0-0 2.30.2-4 libgirepository-1.0-1 1.31.1-1 python-gi 3.0.3-1
Version: 2.30.x