Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

OpenSesame4 plugin and extension

Hi,

I am working on updating a plugin and extension for OpenSesame 4. It concerns a custom plugin with extension for communicating with a custom USB marker device that replaces the parallel port for sending markers. The plugin is used to initialize the device and send markers. I added an extension which, after the experiment is finished, opens a tab and presents a table of all the markers that were sent. For OpenSesame 3 I already created this, and everything was working fine. Now I am updating it to work with OpenSesame 4 and I ran into some issues:

  • In the OpenSesame 3 version of the plugin I saved several variables in var (self.experiment.var), so that the extension could access them. However, in OpenSesame 4 it seems that I can only save 'simple' variable types in var, like string/integer/float, but for example no lists or dicts. So, what I am doing in OpenSesame 4 is saving variables in the python workspace: self.experiment.python_workspace. This works, but I was wondering why the var variable cannot hold lists or dicts anymore.
  • In the plugin, I added a cleanup function (self.experiment.cleanup_functions.append(my_cleanup_func)). In this cleanup function I save variables in the python workspace (as mentioned above) that are later used in the extension. This works fine when the task runs to completion. However, when an error occurs or when the user aborts the experiment, this does not work. That is, the extension cannot find the variables that were saved in the python workspace during the cleanup function. It seems as if in these occasions the extension runs before the cleanup functions run, so that the variables are not saved yet when the extension is getting them. It is a real mystery to me why this happens only when the experiment crashes or is aborted by the user. It is important that these variables are saved during the cleanup function (or at least at the end of the experiment). How can I save some variables at the end of the experiment (whether it is ended by a crash or not) and have them be used by an extension that listens to event_end_experiment?

Best,

Iris

Comments

  • Hi @labsupport / Iris,

    In the OpenSesame 3 version of the plugin I saved several variables in var (self.experiment.var), so that the extension could access them. However, in OpenSesame 4 it seems that I can only save 'simple' variable types in var, like string/integer/float, but for example no lists or dicts. So, what I am doing in OpenSesame 4 is saving variables in the python workspace: self.experiment.python_workspace. This works, but I was wondering why the var variable cannot hold lists or dicts anymore.

    As of OpenSesame 4.0, the var object is deprecated because the Python (or JavaScript) workspace is used for everything. The idea behind this is that this behavior is more intuitive to new users for whom the distinction between the var object and the Python (or JavaScript) workspace may be confusing. (And honestly it only existed because of old technical limitations that no longer exist.)

    The var object still exists for backwards compatibility, but now it is essentially a wrapper around the Python workspace. Variables that are assigned to the var object are converted to simple types that the logger can handle to make sure that they are always logged, as they were also previously. (Although previously this conversion only happened during logging and not during assignment.)

    In other words, there is a slight change in behavior that most users won't notice but that does affect your plugin. For your plugin, I would recommend using the python_workspace object for everything that you want to make available to the user, and take into account that simple variable types will be logged but other objects won't.

    In the plugin, I added a cleanup function (self.experiment.cleanup_functions.append(my_cleanup_func)). (...) It is a real mystery to me why this happens only when the experiment crashes or is aborted by the user. It is important that these variables are saved during the cleanup function (or at least at the end of the experiment). How can I save some variables at the end of the experiment (whether it is ended by a crash or not) and have them be used by an extension that listens to event_end_experiment?

    When the experiment crashes because Python crashes, you get an ExperimentProcessDied error. When the user aborts the experiment by clicking on the 'Kill experiment' button, the Python process is explicitly killed, which in a sense is similar to Python crashing. In both of these cases, clean-up functions are not executed, because the process in which they would be executed is simply gone.

    If you want to be sure that clean-up like behavior is always performed, also when the experiment processes crashes or is killed, then you will have to think of some workaround, for example by periodically writing data to a temporary file and having the extension check this file afterwards.

    In contrast, when the experiment crashes due to another error, say because of a non-existing variable reference, or when the user aborts the experiment by pressing Escape, clean-up function should be executed though, because in these cases the experiment process is neatly closed rather than killed.

    With that in mind, could you verify that this is indeed the behavior that you're seeing?

    — Sebastiaan

    Buy Me A Coffee

  • Dear @sebastiaan,

    In other words, there is a slight change in behavior that most users won't notice but that does affect your plugin. For your plugin, I would recommend using the python_workspace object for everything that you want to make available to the user, and take into account that simple variable types will be logged but other objects won't.

    Thank you for the explanation about the var object. We will use the python_workspace from now on.

    If you want to be sure that clean-up like behavior is always performed, also when the experiment processes crashes or is killed, then you will have to think of some workaround, for example by periodically writing data to a temporary file and having the extension check this file afterwards.

    With regard to periodically writing data, this is unfortunately not an option for us, since writing the data would result in a (relatively large) delay, and our code is quite time sensitive. We will try to come up with some other workaround.

    With that in mind, could you verify that this is indeed the behavior that you're seeing?

    Unfortunately, the cleanup does not behave as you described. When code execution fails because of (for example) a non-existing variable, or when we abort the experiment by pressing Escape, the clean up function is not executed.

    Thanks in advance!

    Kind regards,

    Iris

  • Hi @labsupport ,

    Unfortunately, the cleanup does not behave as you described. When code execution fails because of (for example) a non-existing variable, or when we abort the experiment by pressing Escape, the clean up function is not executed.

    Thanks for pointing this out. There was indeed an issue that, while the clean-up functions were executed, the result of this wasn't transferred to the main process. This should be fixed in the next maintenance (4.0.21) release that will appear through the automatic updater. If this doesn't solve this issue, let me know!

    — Sebastiaan

    Buy Me A Coffee

  • Hi @sebastiaan,

    We tried updating through the automatic updater to 4.0.21, but this resulted in some unexplainable errors (see image). I'm assuming we need 4.0.22, but it is not available (yet) through the automatic updater.


    Best,

    Iris

  • Hi @labsupport ,

    This is very odd, but almost certainly unrelated to this update. It seems like some kind of corruption of the user interface, specifically the web-browser component that is used for some things. Does simply restarting the program or the computer make the issue go away? And did you update through the automatic updater (which updates only selected packages and not their dependencies) or manually (which by default also updates dependencies, which can break things)?

    I'm assuming we need 4.0.22, but it is not available (yet) through the automatic updater.

    The fix was already in 4.0.21. I just followed up with another very minor bugfix related to forms.

    — Sebastiaan

    Buy Me A Coffee

  • Hi @sebastiaan,

    It was installed with the automatic updater, restarting the program and computer did not make the issue go away, we'll try reinstalling OpenSesame on that pc. On two other pc's, the automatic updater icon or pop-up never shows, so I tried manually updating, and that worked. I can confirm that the clean-up function is now behaving as it should, thank you for fixing this!

    Best,

    Iris

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games