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):
32
32
"""
33
33
LocalBox is a CodeBox implementation that runs code locally using IPython.
34
34
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
35
39
"""
36
40
41
+ _instance : t .Optional ["LocalBox" ] = None
42
+
37
43
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
40
56
41
57
def __init__ (
42
58
self ,
You can’t perform that action at this time.
0 commit comments