Skip to content

Commit 71546b8

Browse files
committed
Close #70 by ikotler: Pythonect now supports Max Threads Limit
1 parent ea20424 commit 71546b8

5 files changed

Lines changed: 307 additions & 207 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ HEAD
1111

1212
- Issue #58: Install argparse if Python 2.6
1313

14+
- Feature #70: Pythonect now supports Max Threads Limit (i.e. '--mt' command-line argument)
15+
1416

1517
What's New In Pythonect 0.4.2?
1618
==============================

‎bin/pythonect‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import logging
3636
import os
3737
import atexit
3838
import runpy
39+
import multiprocessing
3940

4041

4142
try:
@@ -149,7 +150,7 @@ class PythonectInteractiveConsole(code.InteractiveConsole):
149150

150151
def main():
151152

152-
locals_ = {}
153+
locals = {}
153154

154155
verbose_levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
155156

@@ -168,6 +169,7 @@ def main():
168169
parser.add_argument('--interactive', '-i', action='store_true', default=False, help='inspect interactively after running script')
169170
parser.add_argument('--command', '-c', metavar='cmd', nargs='*', help='program passed in as string')
170171
parser.add_argument('--module', '-m', metavar='mod', action='store', help='run library module as a script')
172+
parser.add_argument('--max-threads-per-flow', '-mt', metavar='N', default=multiprocessing.cpu_count() + 1, type=int, action='store', help='max threads per flow')
171173

172174
args = parser.parse_args()
173175

@@ -183,27 +185,27 @@ def main():
183185

184186
sys.argv = ['']
185187

186-
# Add current working directory to sys.path
187-
188-
sys.path.insert(0, os.getcwd())
189-
190188
# Module as script mode (i.e. python -m 'os')
191189

192190
if args.module:
193191

194-
locals_ = runpy.run_module(args.module)
192+
locals = runpy.run_module(args.module)
193+
194+
# Max threads per pipe
195+
196+
locals.update(__MAX_THREADS_PER_FLOW__=args.max_threads_per_flow)
195197

196198
# Command line mode (i.e. ./pythonect -c "'Hello world' -> print")
197199

198200
if args.command:
199201

200-
pythonect.eval(args.command[0], globals(), locals_)
202+
pythonect.eval(args.command[0], globals(), locals)
201203

202204
# Script-mode (i.e. ./pythonect script or #!/usr/bin/env pythonect)
203205

204206
if args.script:
205207

206-
pythonect.eval(args.script.read().replace('\\\n', ''), globals(), locals_)
208+
pythonect.eval(args.script.read().replace('\\\n', ''), globals_, locals_)
207209

208210
args.script.close()
209211

@@ -219,11 +221,15 @@ def main():
219221

220222
if args.interactive:
221223

224+
# Add current working directory to sys.path
225+
226+
sys.path.insert(0, os.getcwd())
227+
222228
# Pythonect's Banner (for -V, --version purposes)
223229

224230
banner = """Python %s\n[Pythonect %s] on %s\nType "help", "copyright", "credits" or "license" for more information.""" % (sys.version.split('\n')[0], pythonect.__version__, sys.platform)
225231

226-
PythonectInteractiveConsole(locals_).interact(banner)
232+
PythonectInteractiveConsole(locals).interact(banner)
227233

228234
return 0
229235

0 commit comments

Comments
 (0)