load_file() and purge()

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

load_file() and purge()

Salikhov Dinislam
Hi!

Let's assume there is a module forty_two.beam loaded by VM.
Then the module is updated and hot loaded:
     > code:load_file(forty_two).
     {module, forty_two}

Then let's assume that there is no process using an old version of the
module (for example, the module contains only pure functions).
Despite of that following attempt to update the module fails:
     > code:load_file(forty_two).
     Loading of forty_two.beam failed: not_purged
     {error,not_purged}

Is there any rationale why the old code is not automatically purged?
IMO, it would be convenient if _unused_ old version of the code would be
implicitly removed in such case.

Salikhov Dinislam
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: load_file() and purge()

Alex S.

> 25 нояб. 2016 г., в 15:20, Salikhov Dinislam <[hidden email]> написал(а):
>
> Hi!
>
> Let's assume there is a module forty_two.beam loaded by VM.
> Then the module is updated and hot loaded:
>    > code:load_file(forty_two).
>    {module, forty_two}
>
> Then let's assume that there is no process using an old version of the module (for example, the module contains only pure functions).
Even pure functions are executed by the process, and the process can run out of reductions in the middle of that, and stall potentially indefinitely.
To detect old code would require not only checking execution states, but also funs (which no longer kill the process, but cease working, and that may be undesired).

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: load_file() and purge()

Per Hedeland
In reply to this post by Salikhov Dinislam
On 2016-11-25 13:20, Salikhov Dinislam wrote:

>
> Let's assume there is a module forty_two.beam loaded by VM.
> Then the module is updated and hot loaded:
>     > code:load_file(forty_two).
>     {module, forty_two}
>
> Then let's assume that there is no process using an old version of the module (for example, the module contains only pure functions).
> Despite of that following attempt to update the module fails:
>     > code:load_file(forty_two).
>     Loading of forty_two.beam failed: not_purged
>     {error,not_purged}
>
> Is there any rationale why the old code is not automatically purged?

code:load_file/1 *never* purges old code. Try the handy shell function
l/1, defined in c.erl:

l(Mod) ->
    code:purge(Mod),
    code:load_file(Mod).

> IMO, it would be convenient if _unused_ old version of the code would be implicitly removed in such case.

You could define your own load function with appropriate use of
code:soft_purge/1 for that.

--Per Hedeland
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: load_file() and purge()

Salikhov Dinislam
On 11/25/2016 03:38 PM, Per Hedeland wrote:

> On 2016-11-25 13:20, Salikhov Dinislam wrote:
>> Let's assume there is a module forty_two.beam loaded by VM.
>> Then the module is updated and hot loaded:
>>      > code:load_file(forty_two).
>>      {module, forty_two}
>>
>> Then let's assume that there is no process using an old version of the module (for example, the module contains only pure functions).
>> Despite of that following attempt to update the module fails:
>>      > code:load_file(forty_two).
>>      Loading of forty_two.beam failed: not_purged
>>      {error,not_purged}
>>
>> Is there any rationale why the old code is not automatically purged?
> code:load_file/1 *never* purges old code. Try the handy shell function
> l/1, defined in c.erl:
>
> l(Mod) ->
>      code:purge(Mod),
>      code:load_file(Mod).
Yes, I know that. I'd like to know why load_file() is implemented this way.
IMHO, in the case I've provided soft_purge() could be nicely called by
load_file() to ease programmer's life :)
>> IMO, it would be convenient if _unused_ old version of the code would be implicitly removed in such case.
> You could define your own load function with appropriate use of
> code:soft_purge/1 for that.
>
> --Per Hedeland

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: load_file() and purge()

Per Hedeland
On 2016-11-25 13:45, Salikhov Dinislam wrote:

> On 11/25/2016 03:38 PM, Per Hedeland wrote:
>> On 2016-11-25 13:20, Salikhov Dinislam wrote:
>>> Let's assume there is a module forty_two.beam loaded by VM.
>>> Then the module is updated and hot loaded:
>>>      > code:load_file(forty_two).
>>>      {module, forty_two}
>>>
>>> Then let's assume that there is no process using an old version of the module (for example, the module contains only pure functions).
>>> Despite of that following attempt to update the module fails:
>>>      > code:load_file(forty_two).
>>>      Loading of forty_two.beam failed: not_purged
>>>      {error,not_purged}
>>>
>>> Is there any rationale why the old code is not automatically purged?
>> code:load_file/1 *never* purges old code. Try the handy shell function
>> l/1, defined in c.erl:
>>
>> l(Mod) ->
>>      code:purge(Mod),
>>      code:load_file(Mod).
> Yes, I know that. I'd like to know why load_file() is implemented this way.

Maybe because it should only do what its name implies...

> IMHO, in the case I've provided soft_purge() could be nicely called by load_file()

But you don't know that it *is* that case until you have called
soft_purge()... - determining that the old code is not being used is not
zero cost, and other users of the function may prefer that the decision
to do that is left to them.

> to ease programmer's life :)

IME, the programmer's life is most eased by functions that do 0 or 1
thing, and make it trivial (by return value or failure) to determine
which, rather than functions that do 0, 1, or 2 things, and require
analysis (maybe even of a *combination* of return value and failure) to
determine what they actually did.

The *shell user's* life on the other hand might perhaps be eased by a
programmer providing a function like the one below.

--Per

>>> IMO, it would be convenient if _unused_ old version of the code would be implicitly removed in such case.
>> You could define your own load function with appropriate use of
>> code:soft_purge/1 for that.
>>
>> --Per Hedeland

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions