main icon indicating copy to clipboard operation
main copied to clipboard

reloading a module which module file was unlinked causes crash

Open ironpythonbot opened this issue 10 years ago • 2 comments

E:\2.5test\ironpythonCompatableFor2.5\25\Lib>ipy
IronPython console: IronPython 2.0A6 (2.0.11102.00) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.

import os
from test.test_support import TESTFN
source = TESTFN+os.extsep+";py";
f=open(source,";w";)
print >> f, ";# This tests Python's ability to import a.py file.";
print >>f,";a=3";
print >>f,";b=";, 4
f.close()
source
' [ @test.py' mod ](mailto:@test.py'

mod) =import(TESTFN)
reload(mod)

os.unlink(source)
reload(mod)
Unhandled exception:
Traceback (most recent call last):
ValueError: Invalid argument value
Parameter name: start

E:\2.5test\ironpythonCompatableFor2.5\25\Lib>python
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win
32
Type ";help";, ";copyright";, ";credits"; or ";license"; for more information.
import os
from test.test_support import TESTFN
source = TESTFN +os.extsep +";py";
f=open(source,";w";)
print >> f, ";# This tests Python's ability to import a.py file.";
print >>f,";a=3";
print >>f,";b=";, 4
f.close()
source
' [ @test.py' mod ](mailto:@test.py'

mod) = import(TESTFN)

notice:the file @test.pyc had generated in above

line, but didn't in IronPython

...
os.unlink(source)
reload(mod)

pyc=TESTFN+os.extsep+";pyc";
os.unlink(pyc)
reload(mod)
Traceback (most recent call last):
File ";";, line 1, in
ImportError: No module named @test
^Z

Work Item Details

Original CodePlex Issue: Issue 23893 Status: Active Reason Closed: Unassigned Assigned to: Unassigned Reported on: Jul 28, 2009 at 12:05 AM Reported by: dfugate Updated on: Feb 22, 2013 at 2:12 AM Updated by: jdhardy Custom value: Reported internally at Microsoft. Test: test_import.py CreatedDate: 12/28/2007 NewInternalID: 409711 OldInternalID: 363679 AreaPath: IronPython\Python25

ironpythonbot avatar Dec 09 '14 17:12 ironpythonbot

On 2011-01-23 03:14:11 UTC, tonyheupel commented:

Same exception but hosted inside of C# using IronPython scripts as plugins. I am using a FileWatcher to detect when an IronPython script changes and calling source.Execute(scope) when it is changed/updated to reload that module. This kills the benefit of the dynamically updating plugin.

ironpythonbot avatar Dec 09 '14 17:12 ironpythonbot

Readable repro code:

import os
TESTFN = "@test"
source = TESTFN + ".py"
with open(source, "w") as f:
    print >> f, ("# This tests Python's ability to import a.py file.")
    print >> f, "a =", 3
mod = __import__(TESTFN)
os.unlink(source)
reload(mod)

However, since we don't support .pyc files so I'm not sure if this is really an issue...

slozier avatar Oct 31 '16 02:10 slozier