Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async freezes in nimqml-application #21

Open
R3D9477 opened this issue Mar 15, 2018 · 13 comments
Open

Async freezes in nimqml-application #21

R3D9477 opened this issue Mar 15, 2018 · 13 comments

Comments

@R3D9477
Copy link

R3D9477 commented Mar 15, 2018

Hi. I strange behavior of async/await operaions, when I called into nimqml-signal.
ChatServer freezes at server.nim:38
chat_server_app.zip

Here is client for test:
async_client_server.zip
(also in this client can be tested server.nim without nimqml and it works fine)

Any ideas?

@dom96
Copy link

dom96 commented Mar 15, 2018

I haven't looked at your code, but I'm guessing you haven't properly integrated into the nimqml event loop? You likely need to call some sort of QML poll function together with the asyncdispatch poll function.

@R3D9477
Copy link
Author

R3D9477 commented Mar 15, 2018

@dom96 well, what I trying to do:

  1. to start server:
...
  proc btnStartClicked*(self: MainWindowHandler, serverPort: int) {.slot.} =
    self.chatServer.start(serverPort)
    serverStartedChanged(self, self.chatServer.started)
...
  1. to call procedure 'start' after button clicked:
...
proc start*(server: Server, serverPort: int) =
  server.socket = newAsyncSocket()
  server.started = true
  server.socket.bindAddr(serverPort.Port)
  server.socket.listen()
  server.loopTask = loop(server)
...
  1. then to launch async task 'loop', who will wait for clients:
...
proc loop(server: Server) {.async.} =
  echo 000000000
  while server.started:
    echo 111111111
    let (netAddr, clientSocket) = await server.socket.acceptAddr()
    echo 222222222
    ...
...

nothing more.

and as result output I have:

0
111111111

client tells me about successfully connection, but in that time server doesn't go to next line echo 222222222

@filcuc
Copy link
Owner

filcuc commented Mar 15, 2018

@r3d9u11 @dom96

Qt is not made (usually) for being called by other threads and you must be careful on doing that.
Usually Qt should "own" the main thread for multiple reasons (initialization of static QtObjects in .so libraries that must be destroyed on app exit thus on the same thread).
Honestly i don't have a lot of experience in integrating Qt with other event loops. The best approach is to separate your async server from the main thread and communicate with an "Actor" like pattern. In the worst case split the server and the UI in two different processes and communicate with a Pipe or ZMQ or nanomsg

@R3D9477
Copy link
Author

R3D9477 commented Mar 15, 2018

@filcuc thanks for hint, I'll try to play with threading. but I'll leave this issue to be open, yet

@R3D9477
Copy link
Author

R3D9477 commented Mar 15, 2018

@dom96 async procedures isn't GC safe? Is it possible to call async procedure from another procedure who called in a new thread via spawn?

@dom96
Copy link

dom96 commented Mar 15, 2018

You can write {.async, gcsafe.}, no?

@R3D9477
Copy link
Author

R3D9477 commented Mar 15, 2018

@dom96 yes, thanks! (sorry I'm a novice in Nim, yet)

@filcuc
Copy link
Owner

filcuc commented Mar 16, 2018

@r3d9u11 @dom96
probably i've just to export the QApplication::processEvents() in the DOtherSide library

@R3D9477
Copy link
Author

R3D9477 commented Mar 19, 2018

@filcuc can it help to solve this situation?

@filcuc
Copy link
Owner

filcuc commented Mar 19, 2018

I will give it a look asap

@filcuc
Copy link
Owner

filcuc commented Oct 3, 2019

with filcuc/dotherside@b6fcb52 in place i can proceed and fix this issue

@R3D9477
Copy link
Author

R3D9477 commented Oct 4, 2019

@filcuc
great news!
can I close this issue?

@filcuc
Copy link
Owner

filcuc commented Oct 4, 2019 via email

arnetheduck pushed a commit to arnetheduck/nimqml-miqt-poc that referenced this issue Feb 11, 2025
feat: QGuiApplication supporting icon() and installEventFilter() meth…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants