@@ -948,9 +948,10 @@ results = lab.run_tasks(runs)
948
948
### Why do I see the following error: ` An attempt has been made to start a new process before the current process has finished ` ?
949
949
950
950
When running labtech in a Python script on Windows, macOS, or any
951
- Python environment using the ` spawn ` multiprocessing start method, you
952
- will see the following error if you do not guard your experiment and
953
- lab creation and other non-definition code with `__ name__ ==
951
+ Python environment using the
952
+ [ ` spawn ` multiprocessing start method] ( https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods ) ,
953
+ you will see the following error if you do not guard your experiment
954
+ and lab creation and other non-definition code with `__ name__ ==
954
955
'__ main__ '`:
955
956
956
957
```
@@ -1000,3 +1001,24 @@ if __name__ == '__main__':
1000
1001
```
1001
1002
1002
1003
For details, see [ Safe importing of main module] ( https://docs.python.org/3/library/multiprocessing.html#multiprocessing-safe-main-import ) .
1004
+
1005
+
1006
+ ### Why do I see the following error: ` AttributeError: Can't get attribute 'YOUR_TASK_CLASS' on <module '__main__' (built-in)> ` ?
1007
+
1008
+ You will see this error (as part of a very long stack trace) when
1009
+ defining and running labtech tasks from an interactive Python shell on
1010
+ Windows or macOS (or more specifically, when
1011
+ [ Python's multiprocessing start method] ( https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods )
1012
+ has been set to ` spawn ` or ` forkserver ` ).
1013
+
1014
+ The solution to this error is to define all of your labtech ` Task `
1015
+ types in a separate ` .py ` Python module file which you can import into
1016
+ your interactive shell session (e.g. ` from my_module import MyTask ` ).
1017
+
1018
+ The reason for this error is that ` spawn ` and ` forkserver ` start
1019
+ methods will not copy the current state of your ` __main__ ` module
1020
+ (which contains the variables you declare interactively in the Python
1021
+ shell, including task definitions) into labtech's task subprocesses.
1022
+ This error does not occur for the ` fork ` start method (the current
1023
+ default on Linux) because forked subprocesses * do* receive the current
1024
+ state of all modules (including ` __main__ ` ) from the parent process.
0 commit comments