File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,27 @@ class LocalBox(CodeBox):
3232 """
3333 LocalBox is a CodeBox implementation that runs code locally using IPython.
3434 This is useful for testing and development.
35+
36+ Only one instance can exist at a time. For parallel execution, use:
37+ - DockerBox for local parallel execution
38+ - Get an API key at codeboxapi.com for hosted parallel execution
3539 """
3640
41+ _instance : t .Optional ["LocalBox" ] = None
42+
3743 def __new__ (cls , * args , ** kwargs ) -> "LocalBox" :
38- # This is a hack to ignore the CodeBox.__new__ factory method.
39- return object .__new__ (cls )
44+ if cls ._instance :
45+ raise RuntimeError (
46+ "Only one LocalBox instance can exist at a time.\n "
47+ "For parallel execution use:\n "
48+ "- Use DockerBox for local parallel execution\n "
49+ "- Get an API key at https://codeboxapi.com for secure remote execution"
50+ )
51+
52+ # This is a hack to ignore the CodeBox.__new__ factory method
53+ instance = object .__new__ (cls )
54+ cls ._instance = instance
55+ return instance
4056
4157 def __init__ (
4258 self ,
You can’t perform that action at this time.
0 commit comments