jesseruth / pyev

Automatically exported from code.google.com/p/pyev
0 stars 0 forks source link

Watchers unexpectedly garbage collected #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This behaves unexpected for a Python app:

loop = ev.default_loop()
ev.Timer(5, 0, loop, timer_cb).start()
loop.loop()

The timer is immediately garbage collected and then stopped.

At casual glance of ev.c, it would seem appropriate to PyINCREF on start
and PyDECREF on stop -- this corresponds to adding and removing the timer
from the loop event array.

Having the timer collected in the line above is harmless as the dealloc
calls the ev_timer_stop call, but it's unorthodox behavior for Python app
to introduce concerns about object ownership and garbage collection.

Original issue reported on code.google.com by g%rre.tt@gtempaccount.com on 14 Feb 2009 at 3:31

GoogleCodeExporter commented 9 years ago
Again, let me apologize for the delay.

> Having the timer collected in the line above is harmless as the dealloc
> calls the ev_timer_stop call, but it's unorthodox behavior for Python app
> to introduce concerns about object ownership and garbage collection.

Well, I would argue the opposite :)

If I do not own a reference to an object I expect the garbage collector to free 
it as
soon as possible. In fact,  I got so used to this behaviour that I often find 
myself
writing txt = open("/path/to/file", "r").read() knowing that the file will be 
closed
and collected as soon as it has been read. I know, the situation is a bit 
different
here but I couldn't find an example that would support your position in python 
core
or std lib.

On a side note I tried, in early versions of pyev written with pyrex, to 
implement
what you suggest, it ended up in a mess of ref management and memleaks (what 
happens
if you never call stop() on a watcher to which you own a ref?, etc).

Marking this as invalid. You can reopen if you feel like it, but please come up 
with
a usage example from core that would support your "unorthodox behavior" claim :)

Thanks for the report

malek

Original comment by lekma...@gmail.com on 12 Mar 2009 at 2:23