OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python runpy.run_module exit code

  • Thread starter Thread starter Kees Valkhof
  • Start date Start date
K

Kees Valkhof

Guest
Is it possible to get the exit code from a module called through runpy.run_module()?

I wish to replace my exit_code = subprocess.call('py -m mymodule') with runpy.run_module('mymodule') and still get the exit_code value.

Where mymodule is a directory containing a python script __main__.py which just does sys.exit(1)

Testing runpy.run_module('mymodule') in an interactive shell closes that shell. I could not find any documentation on that behavior. To me it looks like that the difference between using subprocess.call and runpy.run_module is running it as a program or function. If that is the case then the behavior is explained and it is unlikely that I can use runpy.run_module if I need the exit code. Can anyone confirm this, possibly with a link to some documentation where I could have found it.
<p>Is it possible to get the exit code from a module called through runpy.run_module()?</p>

<p>I wish to replace my
<code>
exit_code = subprocess.call('py -m mymodule')
</code>
with
<code>
runpy.run_module('mymodule')
</code>
and still get the <code>exit_code</code> value.</p>

<p>Where <code>mymodule</code> is a directory containing a python script <code>__main__.py</code> which just does <code>sys.exit(1)</code></p>

<p>Testing <code>runpy.run_module('mymodule')</code> in an interactive shell closes that shell. I could not find any documentation on that behavior. To me it looks like that the difference between using <code>subprocess.call</code> and <code>runpy.run_module</code> is running it as a program or function. If that is the case then the behavior is explained and it is unlikely that I can use <code>runpy.run_module</code> if I need the exit code.
Can anyone confirm this, possibly with a link to some documentation where I could have found it. </p>
 

Latest posts

A
Replies
0
Views
1
Aarif Hussain A Nassar
A
F
Replies
0
Views
1
Fahmi Nur Fachrurozi
F
Top