[Ironpython-users] Recreate and compile a script in an existing engine instance?

Markus Schaber m.schaber at codesys.com
Mon Jul 14 16:55:40 CEST 2014


Hi, Andrew,

According to my experiences, the FileSystemWatcher are only of limited use without additional precautions.

They fire "eventually" after a file modification took place (the write access happened). This does not imply that

1.     The modifying program has finished its modifications – it could be still issuing further write requests to complete its work.

2.     The modifying program has closed the file handle. (By default, windows blocks concurrent access to the files.)

3.     No one else has started modifying the file in the meantime (including the next "cycle of the original modifying program).

Most of the time, one wishes some "Notify me when the modifying program has closed the file handle, and atomically give me a file handle" event.

Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] Im Auftrag von Andrew Stephens
Gesendet: Montag, 14. Juli 2014 16:13
An: Jeff Hardy
Cc: ironpython-users at python.org
Betreff: Re: [Ironpython-users] Recreate and compile a script in an existing engine instance?

I think I’ve found the cause of the problem. I recreate the script source and compile it within the FileSystemWatcher.Changed event. I can only assume that the file is still locked or is still being written to as this event fires - adding even a very small Thread.Sleep() seems to have fixed it.


From: Jeff Hardy [mailto:jdhardy at gmail.com]
Sent: 14 July 2014 13:03
To: Andrew Stephens
Cc: ironpython-users at python.org<mailto:ironpython-users at python.org>
Subject: Re: [Ironpython-users] Recreate and compile a script in an existing engine instance?

Smells like a bug, because this should work. Can you open an issue (https://ironpython.codeplex.com/WorkItem/Create) with a minimal test case that reproduces it?

- Jeff

On Fri, Jul 11, 2014 at 11:58 AM, Andrew Stephens <Andrew.Stephens at nu-ins.com<mailto:Andrew.Stephens at nu-ins.com>> wrote:
In C# I’m loading and compiling a script like this:-

            _engine = Python.CreateEngine();
            _scope = _engine.CreateScope();

            _scriptSource = _engine.CreateScriptSourceFromFile(filename, Encoding.UTF7, SourceCodeKind.Statements);
            _compiledScript = _scriptSource.Compile();

(At some point in time my application will run the script by calling _compiledScript.Execute(_scope).)

I’ve also got a FileSystemWatcher watching the script file. When the file changes I recreate the ScriptSource and compile, basically executing those last two lines again. When I do this, _scriptSource.Compile() throws an ArgumentException (“Invalid argument valueParameter name: start”). The stack trace is below. It works if I re-create *everything* – the engine, scope, script source, compile, but this seems a bit a wasteful. Am I missing something?

Stack trace:-
   at Microsoft.Scripting.Utils.ContractUtils.Requires(Boolean precondition, String paramName)
   at Microsoft.Scripting.SourceUnit.GetCodeLines(Int32 start, Int32 count)
   at Microsoft.Scripting.SourceUnit.GetCodeLine(Int32 line)
   at Microsoft.Scripting.SyntaxErrorException..ctor(String message, SourceUnit sourceUnit, SourceSpan span, Int32 errorCode, Severity severity)
   at Microsoft.Scripting.Hosting.ErrorListenerProxySink.Add(SourceUnit sourceUnit, String message, SourceSpan span, Int32 errorCode, Severity severity)
   at IronPython.Compiler.Parser.CreateParserWorker(CompilerContext context, PythonOptions options, Boolean verbatim)
   at IronPython.Compiler.Parser.CreateParser(CompilerContext context, PythonOptions options)
   at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)
   at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
   at IronPython.Runtime.PythonContext.CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Compile(CompilerOptions options, ErrorSink errorSink)
   at Microsoft.Scripting.SourceUnit.Compile(ErrorSink errorSink)
   at Microsoft.Scripting.Hosting.ScriptSource.CompileInternal(CompilerOptions compilerOptions, ErrorListener errorListener)
   at Microsoft.Scripting.Hosting.ScriptSource.Compile()




Andrew Stephens

Senior Software Engineer

Nu Instruments Ltd


Email:

Andrew.Stephens at nu-ins.com<mailto:Andrew.Stephens at nu-ins.com>

Tel:

+44 (0) 1978 661304<tel:%2B44%20%280%29%201978%20661304>

Fax:

+44 (0) 1978 664301<tel:%2B44%20%280%29%201978%20664301>

Web:

www.nu-ins.com<http://www.nu-ins.com>



[cid:image001.png at 01CF9F83.270D7800]



Nu Instruments Ltd
Unit 74 Clywedog Road South
Wrexham Industrial Estate
Wrexham LL13 9XS
United Kingdom

Disclaimer

This message is confidential and may contain privileged information and is protected by copyright. If you are not the intended recipient you should not copy or disclose this message to anyone but should kindly notify the sender and delete the message. Opinions, conclusions and other information in this message which do not relate to the official business of Nu Instruments Ltd shall be understood as neither given nor endorsed by it. No contracts shall be concluded by means of this email. Neither the Company nor the sender accepts any responsibility or liability for any loss or damage arising from the presence of any computer virus or similar harmful code contained in this email or attachment/s.  It is your responsibility to scan this email and any attachments. The Company reserves the right to access and disclose all messages sent over its email system.

Nu Instruments Ltd is registered in England, No.: 3046042. Registered Office: Seacourt Tower, West Way, Oxford OX2 0FB. VAT No.: GB 616 3733 45




Andrew Stephens

Senior Software Engineer

Nu Instruments Ltd


Email:

Andrew.Stephens at nu-ins.com<mailto:Andrew.Stephens at nu-ins.com>

Tel:

+44 (0) 1978 661304

Fax:

+44 (0) 1978 664301

Web:

www.nu-ins.com<http://www.nu-ins.com>




[cid:image001.png at 01CF9F83.270D7800]



Nu Instruments Ltd
Unit 74 Clywedog Road South
Wrexham Industrial Estate
Wrexham LL13 9XS
United Kingdom

Disclaimer

This message is confidential and may contain privileged information and is protected by copyright. If you are not the intended recipient you should not copy or disclose this message to anyone but should kindly notify the sender and delete the message. Opinions, conclusions and other information in this message which do not relate to the official business of Nu Instruments Ltd shall be understood as neither given nor endorsed by it. No contracts shall be concluded by means of this email. Neither the Company nor the sender accepts any responsibility or liability for any loss or damage arising from the presence of any computer virus or similar harmful code contained in this email or attachment/s.  It is your responsibility to scan this email and any attachments. The Company reserves the right to access and disclose all messages sent over its email system.

Nu Instruments Ltd is registered in England, No.: 3046042. Registered Office: Seacourt Tower, West Way, Oxford OX2 0FB. VAT No.: GB 616 3733 45
_______________________________________________
Ironpython-users mailing list
Ironpython-users at python.org<mailto:Ironpython-users at python.org>
https://mail.python.org/mailman/listinfo/ironpython-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140714/6fe115fb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 7347 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140714/6fe115fb/attachment.png>


More information about the Ironpython-users mailing list