`wait(stats=True)` behaves weird if written in the root of the `__main__` module
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 184
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
I was playing with BocPy and got some weird behaviour when using wait(stats=True) in the root of the __main__ module. Calling wait(stats=True) works just fine, but storing the result in a global variable stats = wait(stats=True) causes an exception AttributeError: 'NoneType' object has no attribute 'join'
Here is a the small example
from bocpy import Cown, when, wait
c = Cown([1, 2, 3])
def main():
@when(c)
def x(c):
print(f"1: {hex(id(c.value))}: {c.value}")
if __name__ == "__main__":
main()
wait(stats=True) # Is fine
if __name__ == "__main__":
main()
stats = wait(stats=True) # Runtime Error
For me, this results in the following exception:
Traceback (most recent call last):
File "<workspace>/bocpy/pyrona.py", line 11, in <module>
main()
~~~~^^
File "<workspace>/bocpy/pyrona.py", line 6, in main
@when(c)
~~~~^^^
File "<workspace>/bocpy/src/bocpy/behaviors.py", line 1990, in when_factory
start(module=get_caller_module())
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<workspace>/bocpy/src/bocpy/behaviors.py", line 1960, in start
BEHAVIORS.start(module)
~~~~~~~~~~~~~~~^^^^^^^^
File "<workspace>/bocpy/src/bocpy/behaviors.py", line 1034, in start
exec(
~~~~^
compile(export.code, main_export_file, "exec"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
main_export.__dict__,
^^^^^^^^^^^^^^^^^^^^^
)
^
File "<bocpy:main:__main__>", line 9, in <module>
stats = wait(stats=True)
File "<workspace>/bocpy/src/bocpy/behaviors.py", line 2134, in wait
BEHAVIORS.stop(_remaining())
~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "<workspace>/bocpy/src/bocpy/behaviors.py", line 1390, in stop
self.noticeboard.join(_remaining())
^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'join'
This can be fixed by moving the wait into the main() function, but it's still a bit weird.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/bocpy/behaviors.py at wait(), stop(), when_factory(), and start(), following the traceback from the provided root-level example. Reproduce both wait(stats=True) forms and inspect why the second path reaches a None noticeboard. Done means the example no longer raises AttributeError and the wait result can be assigned successfully, with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 63/100