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

"dramatiq worker" runs code that doesn't exist (weird cache) #644

Open
gtavella opened this issue Jul 22, 2024 · 0 comments
Open

"dramatiq worker" runs code that doesn't exist (weird cache) #644

gtavella opened this issue Jul 22, 2024 · 0 comments

Comments

@gtavella
Copy link

gtavella commented Jul 22, 2024

Problem: dramatiq runs code that doesn't exist.

It runs code that existed but does not exist anymore. This weird behavior seems very persistent.

Explanation

Weird behavior persists despite:

  • I've uninstalled and installed dramatiq
  • Restarted terminal, editor, flask server, machine
  • I've deleted the ENTIRE database instance, redis is gone
  • I've deleted the redis url from my .env
  • I don't have any other modules named like the modules I run as worker
  • Deleted all pycache folders, there are no hidden files
  • The files are auto-saved
  • With or without git
  • Same behavior with powershell, command prompt, git bash
  • Ended all python processes from task manager
  • dramatiq is installed in virtual envs only, no global
  • Removed all keys in redis, there are no keys
  • I've never had a problem like this with flask

And yet, it's like it's holding on to some code.

When I noticed a difference

  1. I create a new virtual env, install dramatiq and redis
  2. First time it works, worker starts
  3. Then I leave the file empty except for a dummy print statement
  4. Running dramatiq worker runs both the print statement as well as the previous code (that was just deleted or commented out)

Also:

  • When I delete the entire file worker.py, running dramatiq worker throws a standard ModuleNotFoundError: No module named 'worker'
  • When I recreate the file from scratch with just the print statement, running dramatiq worker has the same weird behavior: it runs the module plus the code that was deleted
  • This should indicate that this weird caching mechanism is sensitive to file deletion, but not the file editing (so it seems)

So when I create a new virtual env (even if the module name is the same, for example worker), it does not manifest this weird behavior (which I imagine is like saying, it works the first time only)

  • Running dramatiq --processes 1 worker runs 1 process, it works correctly

More details:

  • Windows 10.0.22631
  • python 3.11.9
  • dramatiq 1.17.0 (with redis)
  • pip 24.1.2
  • flask 3.0.3
  • Procfile does not have worker process
  • VS Code with virtual env

If this weird caching mechanism persists across terminal, server, machine restart..

If in redis there are no keys associated with dramatiq..

Uninstall dramatiq, killing all python processes, doesn't work either..

What the hell is this? This is madness.

The only thing that seems to show some "expected behavior" is when I first create a new virtual env and run dramatiq the very first time. All subsequent times seem to run non-existent code.

Screenshots

worker.py is just a print statement (it previously had working code for starting a worker)

worker2.py is just a print statement.

Running worker2.py prints "in worker 2" plus whatever code I previously had in worker.py.

Running worker.py prints "in worker 1" plus whatever code I previously had in worker.py.

Sys path

image

VIRTUAL ENV A

worker2.py

image

worker.py

image

Directory structure

image

VIRTUAL ENV B

Before (first time it works)

image

After (then it runs both current file and code I've just deleted)

image

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

1 participant