anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: qtile/qtile
Issue: CPU usage leak

Running qtile master. Over a timespan of about 24 hours, qtile's CPU usage rises from trivially low to nearly 100%. In the worst stages, qtile is non-responsive to keyboard shortcuts, forcing me to kill it externally.


Changed files:
libqtile/widget/battery.py

diff --git a/libqtile/widget/battery.py b/libqtile/widget/battery.py
index e5b0ee94..4e891163 100644
--- a/libqtile/widget/battery.py
+++ b/libqtile/widget/battery.py
@@ -74,11 +74,14 @@ class _Battery(base._TextBox):
             self.log.exception("Failed to get %s" % name)
 
     def _get_param(self, name):
-        if name in self.filenames:
+        if name in self.filenames and self.filenames[name]:
             return self._load_file(self.filenames[name])
-        else:
+        elif name not in self.filenames:
             # Don't have the file name cached, figure it out
-            file_list = BATTERY_INFO_FILES.get(name, [])
+
+            # Don't modify the global list! Copy with [:]
+            file_list = BATTERY_INFO_FILES.get(name, [])[:]
+
             if getattr(self, name, None):
                 # If a file is manually specified, check it first
                 file_list.insert(0, getattr(self, name))
@@ -90,7 +93,10 @@ class _Battery(base._TextBox):
                     self.filenames[name] = file
                     return value
 
-        # If we made it this far, we don't have a valid file. Just return None.
+        # If we made it this far, we don't have a valid file.
+        # Set it to None to avoid trying the next time.
+        self.filenames[name] = None
+
         return None
 
     def _get_info(self):
Repository: qtile/qtile
Issue: lib*.so references in pangocffi.py

When upgrading from 0.9.1 to 0.10.1, I needed to modify the following references for my system (Ubuntu Vivid) in libqtile/pangocffi.py

gobject = ffi.dlopen('libgobject-2.0.so')
pango = ffi.dlopen('libpango-1.0.so')
pangocairo = ffi.dlopen('libpangocairo-1.0.so')


Changed files:
libqtile/pangocffi.py

diff --git a/libqtile/pangocffi.py b/libqtile/pangocffi.py
index e338c37e..5542a888 100644
--- a/libqtile/pangocffi.py
+++ b/libqtile/pangocffi.py
@@ -54,9 +54,9 @@ try:
 except ImportError:
     from libqtile.ffi_build import pango_ffi as ffi
 
-gobject = ffi.dlopen('libgobject-2.0.so')
-pango = ffi.dlopen('libpango-1.0.so')
-pangocairo = ffi.dlopen('libpangocairo-1.0.so')
+gobject = ffi.dlopen('libgobject-2.0.so.0')
+pango = ffi.dlopen('libpango-1.0.so.0')
+pangocairo = ffi.dlopen('libpangocairo-1.0.so.0')
 
 
 def CairoContext(cairo_t):
Repository: qtile/qtile
Issue: Launching applications that require stdin input hangs qtile

Some applications like bashbug causes qtile to hangup. And the only way out is to kill X. Happens regardless if the program was launched by qtile or any other app.


Changed files:
libqtile/manager.py, libqtile/widget/launchbar.py

diff --git a/libqtile/manager.py b/libqtile/manager.py
index cea9fb79..6aeb4fa6 100644
--- a/libqtile/manager.py
+++ b/libqtile/manager.py
@@ -1174,7 +1174,11 @@ class Qtile(command.CommandObject):
 
                 spawn("firefox")
         """
-        pid, _, _, _ = gobject.spawn_async([os.environ['SHELL'], '-c', cmd])
+        pid, _, _, _ = gobject.spawn_async(
+            [os.environ['SHELL'], '-c', cmd],
+            flags=(gobject.SPAWN_STDOUT_TO_DEV_NULL |
+                   gobject.SPAWN_STDERR_TO_DEV_NULL)
+        )
         return str(pid)
 
     def cmd_status(self):
diff --git a/libqtile/widget/launchbar.py b/libqtile/widget/launchbar.py
index 151a69ca..48913062 100644
--- a/libqtile/widget/launchbar.py
+++ b/libqtile/widget/launchbar.py
@@ -16,7 +16,6 @@ from libqtile import bar
 from libqtile.widget import base
 import os.path
 import cairo
-import gobject
 from xdg.IconTheme import getIconPath
 
 
@@ -129,7 +128,7 @@ class LaunchBar(base._Widget):
                 if cmd.startswith('qsh:'):
                     eval(cmd[4:])
                 else:
-                    gobject.spawn_async([os.environ['SHELL'], '-c', cmd])
+                    self.qtile.cmd_spawn(cmd)
             self.draw()
 
     def draw(self):
Repository: idsia/sacred
Issue: With repeated experiments, the TinyDB observer only logs the last one

I was trying to automatically run an experiment several times and log the results using the tinydb observer. The code of the experiment follows here (test.py):
```python
import numpy as np
from sacred import Experiment
from sacred.observers import TinyDbObserver

ex = Experiment('normal_experiment')
ex.observers.append(TinyDbObserver.create('sacred_results'))

@ex.config
def cfg():
  mu = 0.0
  std = 1.0

@ex.automain
def run(mu, std):
    return np.random.normal(loc=mu, scale=std)
```

I run it 3 times with slightly different parameters like so:
```python
from test import ex

ex.run()
ex.run(config_updates={'mu': 0.5})
ex.run(config_updates={'mu': 15})
```

When I inspect the database afterwards, there is only 1 entry corresponding to the last run.

I have also found that when I recreate the observer every time like so:
```python
from test import ex
from sacred.observers import TinyDbObserver

ex.run()
del ex.observers[0]
ex.observers.append(TinyDbObserver.create('sacred_results'))

ex.run(config_updates={'mu': 0.5})
del ex.observers[0]
ex.observers.append(TinyDbObserver.create('sacred_results'))

ex.run(config_updates={'mu': 15})
```
all 3 entries are logged correctly.

I am not sure whether this is a bug, or whether I am perhaps not using the API as intended.


Changed files:
sacred/observers/tinydb_hashfs.py

diff --git a/sacred/observers/tinydb_hashfs.py b/sacred/observers/tinydb_hashfs.py
index f4896c1..6d8c5eb 100644
--- a/sacred/observers/tinydb_hashfs.py
+++ b/sacred/observers/tinydb_hashfs.py
@@ -127,6 +127,7 @@ class TinyDbObserver(RunObserver):
 
     def started_event(self, ex_info, command, host_info, start_time, config,
                       meta_info, _id):
+        self.db_run_id = None
 
         self.run_entry = {
             'experiment': dict(ex_info),
Repository: idsia/sacred
Issue: config_hook functionality

As far as I understand config_hook should allow me to update configuration immediately before a function is run. So this example should pass:
``` python
from sacred import Experiment

ex = Experiment('hello_config')

@ex.config
def cfg():
    recipient = "world"
    message = "Hello {}!".format(recipient)

@ex.config_hook 
def hook(config, command_name, logger):
    config.update({'recipient': 'me'})
    return config
    
@ex.automain
def main(recipient, message):
    assert recipient == 'me'
``` 

Furthermore it seems that the run_config_hooks statement here https://github.com/IDSIA/sacred/blob/d5d1a1a763c83ffc1cd88e60ff9df79499b3b875/sacred/initialize.py#L385-L416 has no effect as config is not updated in place there.

Changed files:
sacred/initialize.py, tests/test_experiment.py

diff --git a/sacred/initialize.py b/sacred/initialize.py
index b04e521..7f24e9d 100755
--- a/sacred/initialize.py
+++ b/sacred/initialize.py
@@ -102,13 +102,13 @@ class Scaffold(object):
 
         self.get_config_modifications()
 
-    def run_config_hooks(self, config, config_updates, command_name, logger):
+    def run_config_hooks(self, config, command_name, logger):
         final_cfg_updates = {}
         for ch in self.config_hooks:
             cfg_upup = ch(deepcopy(config), command_name, logger)
             if cfg_upup:
                 recursive_update(final_cfg_updates, cfg_upup)
-        recursive_update(final_cfg_updates, config_updates)
+        recursive_update(final_cfg_updates, self.config_updates)
         return final_cfg_updates
 
     def get_config_modifications(self):
@@ -382,8 +382,9 @@ def create_run(experiment, command_name, config_updates=None,
         # update global config
         config = get_configuration(scaffolding)
         # run config hooks
-        config_updates = scaffold.run_config_hooks(config, config_updates,
-                                                   command_name, run_logger)
+        config_hook_updates = scaffold.run_config_hooks(
+            config, command_name, run_logger)
+        recursive_update(scaffold.config, config_hook_updates)
 
     # Phase 4: finalize seeding
     for scaffold in reversed(list(scaffolding.values())):
diff --git a/tests/test_experiment.py b/tests/test_experiment.py
index 5fd902c..2966c15 100755
--- a/tests/test_experiment.py
+++ b/tests/test_experiment.py
@@ -254,3 +254,22 @@ def test_option_hooks_without_options_arg_raises(ex):
         @ex.option_hook
         def invalid_hook(wrong_arg_name):
             pass
+
+
+def test_config_hook_updates_config(ex):
+
+    @ex.config
+    def cfg():
+        a = 'hello'
+
+    @ex.config_hook
+    def hook(config, command_name, logger):
+        config.update({'a': 'me'})
+        return config
+
+    @ex.main
+    def foo():
+        pass
+
+    r = ex.run()
+    assert r.config['a'] == 'me'
Repository: idsia/sacred
Issue: Stdout capturing still randomly fails

There is a persistent bug in the file-descriptor based stdout capturing, that leads to rare non-deterministic test-failures. Probably some form of racing condition. 
I have no idea where things go wrong, so this issue is mostly for documenting the problem. Any ideas are welcome. 

Changed files:
sacred/observers/file_storage.py, sacred/stdout_capturing.py, tests/test_run.py

diff --git a/sacred/observers/file_storage.py b/sacred/observers/file_storage.py
index a4df676..a491d6c 100644
--- a/sacred/observers/file_storage.py
+++ b/sacred/observers/file_storage.py
@@ -215,7 +215,7 @@ class FileStorageObserver(RunObserver):
         try:
             metrics_path = os.path.join(self.dir, "metrics.json")
             saved_metrics = json.load(open(metrics_path, 'r'))
-        except IOError as e:
+        except IOError:
             # We haven't recorded anything yet. Start Collecting.
             saved_metrics = {}
 
diff --git a/sacred/stdout_capturing.py b/sacred/stdout_capturing.py
index f216d88..a0b86db 100644
--- a/sacred/stdout_capturing.py
+++ b/sacred/stdout_capturing.py
@@ -127,11 +127,11 @@ def tee_output_fd():
             # this is done to avoid receiving KeyboardInterrupts (see #149)
             # in Python 3 we could just pass start_new_session=True
             tee_stdout = subprocess.Popen(
-                ['tee', '-a', '/dev/stderr'], preexec_fn=os.setsid,
-                stdin=subprocess.PIPE, stderr=target_fd, stdout=1)
+                ['tee', '-a', target.name], preexec_fn=os.setsid,
+                stdin=subprocess.PIPE, stdout=1)
             tee_stderr = subprocess.Popen(
-                ['tee', '-a', '/dev/stderr'], preexec_fn=os.setsid,
-                stdin=subprocess.PIPE, stderr=target_fd, stdout=2)
+                ['tee', '-a', target.name], preexec_fn=os.setsid,
+                stdin=subprocess.PIPE, stdout=2)
         except (FileNotFoundError, (OSError, AttributeError)):
             # No tee found in this operating system. Trying to use a python
             # implementation of tee. However this is slow and error-prone.
diff --git a/tests/test_run.py b/tests/test_run.py
index 9adc527..8903c0b 100755
--- a/tests/test_run.py
+++ b/tests/test_run.py
@@ -266,4 +266,5 @@ def test_captured_out_filter(run, capsys):
     run.main_function.side_effect = print_mock_progress
     with capsys.disabled():
         run()
+        sys.stdout.flush()
     assert run.captured_out == 'progress 9'