We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Builder 'Aperture' component cannot have indefinite duration
If a Builder 'Aperture' component is set to have an indefinite duration, the actual result is that it is enabled and then immediately disabled. Hence, it has no effect on other stimuli. Below is example code that gets generated when an indefinite duration is specified:

```
# *aperture* updates
if t >= 0.0 and aperture.status == NOT_STARTED:
    # keep track of start time/frame for later
    aperture.tStart = t  # underestimates by a little under one frame
    aperture.frameNStart = frameN  # exact frame index
    aperture.enabled = True
if aperture.status == STARTED and t >= (0.0 + (-win.monitorFramePeriod*0.75)): #most of one frame period left
    aperture.enabled = False
if aperture.status == STARTED:  # only update if being drawn
    aperture.setPos(mouse.getPos(), log=False)
```

The error is in the second if/then above, which should not occur. It is included as if there was a maximum duration in effect, but the value is omitted in the `(-win.monitorFramePeriod*0.75)` expression and hence the duration is effectively zero.

The fix here should be simple but I'm not familiar with playing with the Builder component generation code. So recording the bug here until I can figure out how to fix it (and test).

A work-around for users in the mean time would be to simply put an unfeasibly large number in the duration field (e.g. 9999).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `psychopy/app/builder/components/aperture.py`
Content:
```
1 # Part of the PsychoPy library
2 # Copyright (C) 2015 Jonathan Peirce
3 # Distributed under the terms of the GNU General Public License (GPL).
4 
5 from os import path
6 from ._base import BaseVisualComponent, getInitVals
7 
8 __author__ = 'Jeremy Gray, Jon Peirce'
9 # March 2011; builder-component for Yuri Spitsyn's visual.Aperture class
10 # July 2011: jwp added the code for it to be enabled only when needed
11 
12 # the absolute path to the folder containing this path
13 thisFolder = path.abspath(path.dirname(__file__))
14 iconFile = path.join(thisFolder, 'aperture.png')
15 tooltip = _translate('Aperture: restrict the drawing of stimuli to a given '
16                      'region')
17 
18 
19 class ApertureComponent(BaseVisualComponent):
20     """An event class for using GL stencil to restrict the viewing area to a
21     circle or square of a given size and position"""
22 
23     def __init__(self, exp, parentName, name='aperture', units='norm',
24                  size=1, pos=(0, 0),
25                  startType='time (s)', startVal=0.0,
26                  stopType='duration (s)', stopVal=1.0,
27                  startEstim='', durationEstim=''):
28         # initialise main parameters
29         super(ApertureComponent, self).__init__(
30             exp, parentName, name=name, units=units,
31             pos=pos, size=size,
32             startType=startType, startVal=startVal,
33             stopType=stopType, stopVal=stopVal,
34             startEstim=startEstim, durationEstim=durationEstim)
35 
36         self.type = 'Aperture'
37         self.url = "http://www.psychopy.org/builder/components/aperture.html"
38         # params:
39         # NB make some adjustments on the params defined by _visual component
40         self.order = ['name', 'size', 'pos']  # make sure this is at top
41 
42         msg = _translate("How big is the aperture? (a single number for diameter)")
43         self.params['size'].hint = msg
44         # only localize hints and labels
45         self.params['size'].label = _translate("Size")
46         self.params['pos'].hint = _translate("Where is the aperture centred?")
47 
48         # inherited from _visual component but not needed
49         del self.params['ori']
50         del self.params['color']
51         del self.params['colorSpace']
52         del self.params['opacity']
53 
54     def writeInitCode(self, buff):
55         # do we need units code?
56         if self.params['units'].val == 'from exp settings':
57             unitsStr = ""
58         else:
59             unitsStr = "units=%(units)s, " % self.params
60 
61         # do writing of init
62         inits = getInitVals(self.params)
63 
64         code = ("%(name)s = visual.Aperture(\n"
65                 "    win=win, name='%(name)s',\n"
66                 "    " + unitsStr + "size=%(size)s, pos=%(pos)s)\n"
67                 "%(name)s.disable()  # disable until its actually used\n")
68         buff.writeIndentedLines(code % inits)
69 
70     def writeFrameCode(self, buff):
71         """Only activate the aperture for the required frames
72         """
73 
74         buff.writeIndented("\n")
75         buff.writeIndented("# *%s* updates\n" % (self.params['name']))
76         # writes an if statement to determine whether to draw etc
77         self.writeStartTestCode(buff)
78         buff.writeIndented("%(name)s.enabled = True\n" % self.params)
79         # to get out of the if statement
80         buff.setIndentLevel(-1, relative=True)
81         # writes an if statement to determine whether to draw etc
82         self.writeStopTestCode(buff)
83         buff.writeIndented("%(name)s.enabled = False\n" % self.params)
84         # to get out of the if statement
85         buff.setIndentLevel(-1, relative=True)
86         # set parameters that need updating every frame
87         # do any params need updating? (this method inherited from _base)
88         if self.checkNeedToUpdate('set every frame'):
89             code = ("if %(name)s.status == STARTED:  # only update if being  drawn\n")
90             buff.writeIndented(code % self.params)
91 
92             buff.setIndentLevel(+1, relative=True)  # to enter the if block
93             self.writeParamUpdates(buff, 'set every frame')
94             buff.setIndentLevel(-1, relative=True)  # to exit the if block
95 
96     def writeRoutineEndCode(self, buff):
97         msg = "%(name)s.enabled = False  # just in case it was left enabled\n"
98         buff.writeIndented(msg % self.params)
99
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/psychopy/app/builder/components/aperture.py b/psychopy/app/builder/components/aperture.py
--- a/psychopy/app/builder/components/aperture.py
+++ b/psychopy/app/builder/components/aperture.py
@@ -78,11 +78,12 @@
         buff.writeIndented("%(name)s.enabled = True\n" % self.params)
         # to get out of the if statement
         buff.setIndentLevel(-1, relative=True)
-        # writes an if statement to determine whether to draw etc
-        self.writeStopTestCode(buff)
-        buff.writeIndented("%(name)s.enabled = False\n" % self.params)
-        # to get out of the if statement
-        buff.setIndentLevel(-1, relative=True)
+        if self.params['stopVal'].val not in ['', None, -1, 'None']:
+            # writes an if statement to determine whether to draw etc
+            self.writeStopTestCode(buff)
+            buff.writeIndented("%(name)s.enabled = False\n" % self.params)
+            # to get out of the if statement
+            buff.setIndentLevel(-1, relative=True)
         # set parameters that need updating every frame
         # do any params need updating? (this method inherited from _base)
         if self.checkNeedToUpdate('set every frame'):

{"golden_diff": "diff --git a/psychopy/app/builder/components/aperture.py b/psychopy/app/builder/components/aperture.py\n--- a/psychopy/app/builder/components/aperture.py\n+++ b/psychopy/app/builder/components/aperture.py\n@@ -78,11 +78,12 @@\n         buff.writeIndented(\"%(name)s.enabled = True\\n\" % self.params)\n         # to get out of the if statement\n         buff.setIndentLevel(-1, relative=True)\n-        # writes an if statement to determine whether to draw etc\n-        self.writeStopTestCode(buff)\n-        buff.writeIndented(\"%(name)s.enabled = False\\n\" % self.params)\n-        # to get out of the if statement\n-        buff.setIndentLevel(-1, relative=True)\n+        if self.params['stopVal'].val not in ['', None, -1, 'None']:\n+            # writes an if statement to determine whether to draw etc\n+            self.writeStopTestCode(buff)\n+            buff.writeIndented(\"%(name)s.enabled = False\\n\" % self.params)\n+            # to get out of the if statement\n+            buff.setIndentLevel(-1, relative=True)\n         # set parameters that need updating every frame\n         # do any params need updating? (this method inherited from _base)\n         if self.checkNeedToUpdate('set every frame'):\n", "issue": "Builder 'Aperture' component cannot have indefinite duration\nIf a Builder 'Aperture' component is set to have an indefinite duration, the actual result is that it is enabled and then immediately disabled. Hence, it has no effect on other stimuli. Below is example code that gets generated when an indefinite duration is specified:\n\n```\n# *aperture* updates\nif t >= 0.0 and aperture.status == NOT_STARTED:\n    # keep track of start time/frame for later\n    aperture.tStart = t  # underestimates by a little under one frame\n    aperture.frameNStart = frameN  # exact frame index\n    aperture.enabled = True\nif aperture.status == STARTED and t >= (0.0 + (-win.monitorFramePeriod*0.75)): #most of one frame period left\n    aperture.enabled = False\nif aperture.status == STARTED:  # only update if being drawn\n    aperture.setPos(mouse.getPos(), log=False)\n```\n\nThe error is in the second if/then above, which should not occur. It is included as if there was a maximum duration in effect, but the value is omitted in the `(-win.monitorFramePeriod*0.75)` expression and hence the duration is effectively zero.\n\nThe fix here should be simple but I'm not familiar with playing with the Builder component generation code. So recording the bug here until I can figure out how to fix it (and test).\n\nA work-around for users in the mean time would be to simply put an unfeasibly large number in the duration field (e.g. 9999).\n\n", "before_files": [{"content": "# Part of the PsychoPy library\n# Copyright (C) 2015 Jonathan Peirce\n# Distributed under the terms of the GNU General Public License (GPL).\n\nfrom os import path\nfrom ._base import BaseVisualComponent, getInitVals\n\n__author__ = 'Jeremy Gray, Jon Peirce'\n# March 2011; builder-component for Yuri Spitsyn's visual.Aperture class\n# July 2011: jwp added the code for it to be enabled only when needed\n\n# the absolute path to the folder containing this path\nthisFolder = path.abspath(path.dirname(__file__))\niconFile = path.join(thisFolder, 'aperture.png')\ntooltip = _translate('Aperture: restrict the drawing of stimuli to a given '\n                     'region')\n\n\nclass ApertureComponent(BaseVisualComponent):\n    \"\"\"An event class for using GL stencil to restrict the viewing area to a\n    circle or square of a given size and position\"\"\"\n\n    def __init__(self, exp, parentName, name='aperture', units='norm',\n                 size=1, pos=(0, 0),\n                 startType='time (s)', startVal=0.0,\n                 stopType='duration (s)', stopVal=1.0,\n                 startEstim='', durationEstim=''):\n        # initialise main parameters\n        super(ApertureComponent, self).__init__(\n            exp, parentName, name=name, units=units,\n            pos=pos, size=size,\n            startType=startType, startVal=startVal,\n            stopType=stopType, stopVal=stopVal,\n            startEstim=startEstim, durationEstim=durationEstim)\n\n        self.type = 'Aperture'\n        self.url = \"http://www.psychopy.org/builder/components/aperture.html\"\n        # params:\n        # NB make some adjustments on the params defined by _visual component\n        self.order = ['name', 'size', 'pos']  # make sure this is at top\n\n        msg = _translate(\"How big is the aperture? (a single number for diameter)\")\n        self.params['size'].hint = msg\n        # only localize hints and labels\n        self.params['size'].label = _translate(\"Size\")\n        self.params['pos'].hint = _translate(\"Where is the aperture centred?\")\n\n        # inherited from _visual component but not needed\n        del self.params['ori']\n        del self.params['color']\n        del self.params['colorSpace']\n        del self.params['opacity']\n\n    def writeInitCode(self, buff):\n        # do we need units code?\n        if self.params['units'].val == 'from exp settings':\n            unitsStr = \"\"\n        else:\n            unitsStr = \"units=%(units)s, \" % self.params\n\n        # do writing of init\n        inits = getInitVals(self.params)\n\n        code = (\"%(name)s = visual.Aperture(\\n\"\n                \"    win=win, name='%(name)s',\\n\"\n                \"    \" + unitsStr + \"size=%(size)s, pos=%(pos)s)\\n\"\n                \"%(name)s.disable()  # disable until its actually used\\n\")\n        buff.writeIndentedLines(code % inits)\n\n    def writeFrameCode(self, buff):\n        \"\"\"Only activate the aperture for the required frames\n        \"\"\"\n\n        buff.writeIndented(\"\\n\")\n        buff.writeIndented(\"# *%s* updates\\n\" % (self.params['name']))\n        # writes an if statement to determine whether to draw etc\n        self.writeStartTestCode(buff)\n        buff.writeIndented(\"%(name)s.enabled = True\\n\" % self.params)\n        # to get out of the if statement\n        buff.setIndentLevel(-1, relative=True)\n        # writes an if statement to determine whether to draw etc\n        self.writeStopTestCode(buff)\n        buff.writeIndented(\"%(name)s.enabled = False\\n\" % self.params)\n        # to get out of the if statement\n        buff.setIndentLevel(-1, relative=True)\n        # set parameters that need updating every frame\n        # do any params need updating? (this method inherited from _base)\n        if self.checkNeedToUpdate('set every frame'):\n            code = (\"if %(name)s.status == STARTED:  # only update if being  drawn\\n\")\n            buff.writeIndented(code % self.params)\n\n            buff.setIndentLevel(+1, relative=True)  # to enter the if block\n            self.writeParamUpdates(buff, 'set every frame')\n            buff.setIndentLevel(-1, relative=True)  # to exit the if block\n\n    def writeRoutineEndCode(self, buff):\n        msg = \"%(name)s.enabled = False  # just in case it was left enabled\\n\"\n        buff.writeIndented(msg % self.params)\n", "path": "psychopy/app/builder/components/aperture.py"}], "after_files": [{"content": "# Part of the PsychoPy library\n# Copyright (C) 2015 Jonathan Peirce\n# Distributed under the terms of the GNU General Public License (GPL).\n\nfrom os import path\nfrom ._base import BaseVisualComponent, getInitVals\n\n__author__ = 'Jeremy Gray, Jon Peirce'\n# March 2011; builder-component for Yuri Spitsyn's visual.Aperture class\n# July 2011: jwp added the code for it to be enabled only when needed\n\n# the absolute path to the folder containing this path\nthisFolder = path.abspath(path.dirname(__file__))\niconFile = path.join(thisFolder, 'aperture.png')\ntooltip = _translate('Aperture: restrict the drawing of stimuli to a given '\n                     'region')\n\n\nclass ApertureComponent(BaseVisualComponent):\n    \"\"\"An event class for using GL stencil to restrict the viewing area to a\n    circle or square of a given size and position\"\"\"\n\n    def __init__(self, exp, parentName, name='aperture', units='norm',\n                 size=1, pos=(0, 0),\n                 startType='time (s)', startVal=0.0,\n                 stopType='duration (s)', stopVal=1.0,\n                 startEstim='', durationEstim=''):\n        # initialise main parameters\n        super(ApertureComponent, self).__init__(\n            exp, parentName, name=name, units=units,\n            pos=pos, size=size,\n            startType=startType, startVal=startVal,\n            stopType=stopType, stopVal=stopVal,\n            startEstim=startEstim, durationEstim=durationEstim)\n\n        self.type = 'Aperture'\n        self.url = \"http://www.psychopy.org/builder/components/aperture.html\"\n        # params:\n        # NB make some adjustments on the params defined by _visual component\n        self.order = ['name', 'size', 'pos']  # make sure this is at top\n\n        msg = _translate(\"How big is the aperture? (a single number for diameter)\")\n        self.params['size'].hint = msg\n        # only localize hints and labels\n        self.params['size'].label = _translate(\"Size\")\n        self.params['pos'].hint = _translate(\"Where is the aperture centred?\")\n\n        # inherited from _visual component but not needed\n        del self.params['ori']\n        del self.params['color']\n        del self.params['colorSpace']\n        del self.params['opacity']\n\n    def writeInitCode(self, buff):\n        # do we need units code?\n        if self.params['units'].val == 'from exp settings':\n            unitsStr = \"\"\n        else:\n            unitsStr = \"units=%(units)s, \" % self.params\n\n        # do writing of init\n        inits = getInitVals(self.params)\n\n        code = (\"%(name)s = visual.Aperture(\\n\"\n                \"    win=win, name='%(name)s',\\n\"\n                \"    \" + unitsStr + \"size=%(size)s, pos=%(pos)s)\\n\"\n                \"%(name)s.disable()  # disable until its actually used\\n\")\n        buff.writeIndentedLines(code % inits)\n\n    def writeFrameCode(self, buff):\n        \"\"\"Only activate the aperture for the required frames\n        \"\"\"\n\n        buff.writeIndented(\"\\n\")\n        buff.writeIndented(\"# *%s* updates\\n\" % (self.params['name']))\n        # writes an if statement to determine whether to draw etc\n        self.writeStartTestCode(buff)\n        buff.writeIndented(\"%(name)s.enabled = True\\n\" % self.params)\n        # to get out of the if statement\n        buff.setIndentLevel(-1, relative=True)\n        if self.params['stopVal'].val not in ['', None, -1, 'None']:\n            # writes an if statement to determine whether to draw etc\n            self.writeStopTestCode(buff)\n            buff.writeIndented(\"%(name)s.enabled = False\\n\" % self.params)\n            # to get out of the if statement\n            buff.setIndentLevel(-1, relative=True)\n        # set parameters that need updating every frame\n        # do any params need updating? (this method inherited from _base)\n        if self.checkNeedToUpdate('set every frame'):\n            code = (\"if %(name)s.status == STARTED:  # only update if being  drawn\\n\")\n            buff.writeIndented(code % self.params)\n\n            buff.setIndentLevel(+1, relative=True)  # to enter the if block\n            self.writeParamUpdates(buff, 'set every frame')\n            buff.setIndentLevel(-1, relative=True)  # to exit the if block\n\n    def writeRoutineEndCode(self, buff):\n        msg = \"%(name)s.enabled = False  # just in case it was left enabled\\n\"\n        buff.writeIndented(msg % self.params)\n", "path": "psychopy/app/builder/components/aperture.py"}]}