Python libmm problems

Colin Helliwell colin.helliwell at ln-systems.com
Thu Sep 14 16:38:47 UTC 2017


> On 14 September 2017 at 17:11 Dan Williams <dcbw at redhat.com> wrote:
> 
> On Thu, 2017-09-14 at 15:35 +0100, Colin Helliwell wrote:
> 
..
> > Thanks Dan. I've persevered with GLib, and made a bit of progress.
> > On top of your suggestion - instead of the start-up "modems =
> > manager.get_objects()" etc, I've hooked in [a derivation of] the
> > ModemWatcher example, and pass an instance in the
> > timeout_add_seconds() instead of 'modems[0]'.
> > Getting somewhere under normal circumstances, but I've found that if
> > MM is restarted whilst the script is running, then get_modem_state()
> > no longer gets called at all. The ModemWatcher instance *is* still
> > spotting the presence of the modem, even if I unload its driver after
> > stopping MM and reload it after MM is restarted.
> > Something, I guess, has got unhooked in the event driving...?
> 
> When MM gets restarted, that object is no longer valid because it went
> away when MM quit. So you need to find the new modem. Also, if you're
> using modem paths, you cannot be sure that the modem path from before
> MM restart will be the same modem after MM restart.
> 

So far I've actually been matching on the get_device() i.e. driver.  In my case I don't need to be infinitely flexible - there'll only ever be one physical modem in our [embedded] system.
However, my modified on_object_added() handler - robbed from the example - is doing:
        if self.modem is None:  << is set back to None in the on_object_removed() handler
            modem = obj.get_modem()
            if modem.get_device == MyModemDriver:
                self.modem = modem
so self.modem= is probably the thing I'm not re-doing but - because "that object is no longer valid" - which I *should* be refreshing somehow?

> In any case, one thing you could do is to pass the modem reference to
> the timeout function rather than an actual modem object, and re-look-up
> the modem using that reference every time. A bit inefficient, but if
> you don't want to use signals to listen for MM restarts, that's one
> simple option.
> 

The "modem reference" would be the get_modem() return value? That doesn't become invalid too when MM quits? Even if the modem driver is reloaded whilst MM is restarted....?

I *can* be a little bit dumb with this - it's a script that'll only run at boot-time and then exit [when I figure out how to get a GLib loop to terminate itself!], and tbh there shouldn't be too much dynamic behaviour happening - I was just trying to get it robust to cater for any possible variations in the timing/sequencing of NM startup vs. MM startup vs. modem registration. So to "use signals to listen for MM restarts" might be an excessive investment.
Though I'd ideally prefer to code it 'properly'  :)


More information about the ModemManager-devel mailing list