[QUOTE=Adelle Zhu;52717092]It's just a PyQt GUI app that lives on client workstations. There's a server that's hosting a website and the database that everything interacts with. Originally, I had the workstations checking the database for new rows but there was a race condition involving a workstation setting a new row to old before the others could get to it.
I got rid of that and decided to write a script that lives on the server and does the row checking itself. If it finds one, it just sends a network signal to the workstations to refresh their tables. Ideally, I'd like to have the workstations send a message back to the server confirming the signal.
I'm currently using multiprocessing.connection to do all the networking. It worked briefly before I implemented threading and queues to pass the network object between threads. The script needs to both loop the listening interface and the row query which happens every ten seconds. I've been having problems with blocking functions which I solved by moving things around. Most recently, when the client connects to the socket, the server-side script just ends with exit code 0.
Here's how the server script currently looks, "Maria" is the nickname for the server-script, "Pierre" for the GUI app its communicating with.
[code]
"""
Black Mesa: Project Maria
By smallpants
bitbucket.org/smallpants
"""
import threading
from queue import Queue
from time import sleep
from multiprocessing.connection import Listener
from config import SECRET_KEY
from database import *
"""Server-side signalling for Pierre"""
class Maria:
def __init__(self):
listen_address = ('127.0.0.1', 11718)
self.listener = Listener(listen_address, authkey=SECRET_KEY)
self.has_pierre_connection = False
self.connection = None
self.signal_thread = None
self.listener_thread = None
self.queue = Queue(maxsize=1)
self.listener_thread = threading.Thread(target=self.listen, daemon=True).start()
def listen(self):
if self.queue.empty():
print('connection opened, listening')
self.queue.put(self.listener)
self.signal_thread = threading.Thread(target=self.wait_for_orders, daemon=True).start()
self.listener.accept()
else:
print('listening on existing connection')
def wait_for_orders(self):
self.has_pierre_connection = True
print('waiting for orders')
while self.has_pierre_connection:
print('db checked')
query = session.query(Order).join(Patient, Prescribers, Compound)
orders = query.filter(Order.isNew == 1).count()
if orders > 0:
print('new orders, sending signal')
self.signal_pierre()
else:
session.close()
sleep(10)
def signal_pierre(self):
self.queue.get()
try:
# self.signal_thread.start()
listening.send_bytes(b'new_orders')
orders = session.query(Order).filter(Order.isNew == 1).all()
for order in orders:
setattr(order, 'isNew', 0)
except EOFError:
self.listener.close()
print('Connection broken, listener stopped safely.')
if __name__ == '__main__':
maria = Maria()
[/code][/QUOTE]
Yeah, honestly, it looks like you are trying to implement your own publisher subscribe pattern. I commend you for that, because I think that's not a trivial problem to solve.
Is being updated live important? What do you mean by setting a new row to an old row? I would first imagine that doing a network request to get the updated information for what you need would be the simplest solution that would seem to work
[QUOTE=uriahheep;52712259]Hi, I'm a beginner at programming and I've been trying create a simple social network page with php. I'm confused about how I should model the database. I want to have each user display the list of the profile pictures of their friends on their profile page. Appreciate any help...
Thank you[/QUOTE]
table users ( id, name, age, pic etc ) table users_friends ( user_id, friend_id )..although I don't know how this will hold up when table gets big, although through indexing I guess the queries will still be fast because they know the range they are searching from.
[QUOTE=brianosaur;52719279]Yeah, honestly, it looks like you are trying to implement your own publisher subscribe pattern. I commend you for that, because I think that's not a trivial problem to solve.
Is being updated live important? What do you mean by setting a new row to an old row? I would first imagine that doing a network request to get the updated information for what you need would be the simplest solution that would seem to work[/QUOTE]
I think I'm seriously over complicating this again. After trying things like RabbitMQ, SocketServer and Listener I'm gonna give up on this approach. Right now, I'm going back to the original plan which was to have the clients poll the database themselves. But instead of using an interval scheduler, I'll use a cron trigger in APScheduler. As long as the system time doesn't drift too much, all of the workstations should execute the query at relatively the same time. I can have another method just wait a reasonable amount of time before setting the row to "old", thus avoiding a race condition. A row is marked as new when it's first added to the table so that the clients know the difference between what's been acknowledged and what hasn't. This is not the most explicit way to do things because now I'm back to using timing to ensure this works instead of an event loop.
So I'm not sure of your use case, but it sounds like you have this one site hooked into a db. and multiple clients that use an api from this site to get data from the database? And all the clients have to be updated at the same time?
[QUOTE=brianosaur;52720290]So I'm not sure of your use case, but it sounds like you have this one site hooked into a db. and multiple clients that use an api from this site to get data from the database? And all the clients have to be updated at the same time?[/QUOTE]
Sorta kinda. The DB exists in the middle of everything. Each app, whether it's the website or the software, all have their own users on the DB and they just use SQLAlchemy to interact with it.
Lately, I've been having DB issues involving the website. Some queries return different results in different moments. So if you refresh the dashboard on the website, your table might be missing rows. I think it's an issue with scope. There's a global database session that I don't think I use properly. Rows are persisting in memory when they shouldn't be.
Trying to learn about asp.net core 2.0 / mcv. Does anybody have a good resource or tutorial about it. There's Microsoft's website but I'm looking for anything else that might help me. Thanks!
[QUOTE=Adelle Zhu;52720622]
Lately, I've been having DB issues involving the website. Some queries return different results in different moments. So if you refresh the dashboard on the website, your table might be missing rows. I think it's an issue with scope. There's a global database session that I don't think I use properly. Rows are persisting in memory when they shouldn't be.[/QUOTE]
What rows is it missing? Very recently added rows?
Does SQLAlchemy do any caching by default?
I've returned with another conundrum regarding this small learning project I'm working on.
The closest thing I can relate this program to is diff, except it outputs its content differently. I wanted to have several input lists of various types (contents of a folder, contents of a .txt file, contents of a spreadsheet etc) and have the program perform the following:
1. Check where each record exists
2. Remove the records which exist everywhere
3. Output records which are missing from an input list
It basically checks for discrepancies between multiple lists.
The problem I'm having now is more of a programmatic issue in C++. I decided the best thing to do is create an abstract base class called InputSrc, from which I derived the following classes: Input_Dir, Input_Txt and Input_Xlsx.
InputSrc looks like this (extracted from InputSrc.h):
[code]class InputSrc
{
public:
const std::string m_flag;
std::list<Record> rec_list;
InputSrc(std::string flag);
virtual void read() = 0;
};[/code]
Input_Dir and Input_Txt were easy to derive from the above, as the read() function for each only has to read the entirety of a directory for filenames or the entire contents of a .txt file. The problem I'm facing is with the implementation of Input_Xlsx. For interaction with .xlsx files I'm using a library called xlnt. The simple read() function is not enough for reading a .xlsx file as I need to provide the Input_Xlsx object with the following details:
- spreadsheet path
- worksheet to access
- range to read
- first cell to read
While it would work to just plop those variables into the definition of Input_Xlsx, I would not able to access it via a base class pointer so that I could, for instance, iterate over multiple input lists of various types:
[code]
InputSrc* test = new Input_Xlsx("test/spreadsheet.xlsx");
// the below two lines cause a compilation error as they're not defined in InputSrc
test->setRange("C:C");
test->cursor("C2");
test->read();
[/code]
... that took a while to write down.
My question now is if you know of any better way to structure my program? Did I overcomplicate things? What would be the best way to proceed? Should I just give up and just go back to GMod and play with ZCPU's?
Thank you all in advance!
I also posted this under H&S "Quick Questions" thread as not everyone checks this thread.
[quote]
Weird request, I'm after some kind of framework for creating customised flow graph and nodes within said charts.
[T]http://docs.cryengine.com/download/attachments/1048897/Image1.jpg[/T]
Pretty much what the CryEngine uses. It will be spitting out some weird ass format by the time I'm done with it, I realised a flow graph system just straight up makes perfect sense for what I am doing.
As for the language VB, C/C# or even C++ at a push. Hell I'll use python if such a thing exists, I don't want to make a node system then find something straight up superior.
I've done some research but most things I find are generating flow graphs from existing code, I'll be going in the other direction to a custom format.
[/quote]
I already have a partially created parser before I just straight up stopped when I thought about the old CryEngine's flow graphs.
[QUOTE=tschumann;52728784]What rows is it missing? Very recently added rows?
Does SQLAlchemy do any caching by default?[/QUOTE]
I think I fixed it. I just discovered the value of closing sessions after they've finished querying. Previously, I thought a session's life was the time the app was running, not each time it needs to connect to the DB. So I'm now closing it at the end of a connection.
[QUOTE=supervoltage;52729129]I've returned with another conundrum regarding this small learning project I'm working on.
The closest thing I can relate this program to is diff, except it outputs its content differently. I wanted to have several input lists of various types (contents of a folder, contents of a .txt file, contents of a spreadsheet etc) and have the program perform the following:
1. Check where each record exists
2. Remove the records which exist everywhere
3. Output records which are missing from an input list
It basically checks for discrepancies between multiple lists.
The problem I'm having now is more of a programmatic issue in C++. I decided the best thing to do is create an abstract base class called InputSrc, from which I derived the following classes: Input_Dir, Input_Txt and Input_Xlsx.
InputSrc looks like this (extracted from InputSrc.h):
[code]class InputSrc
{
public:
const std::string m_flag;
std::list<Record> rec_list;
InputSrc(std::string flag);
virtual void read() = 0;
};[/code]
Input_Dir and Input_Txt were easy to derive from the above, as the read() function for each only has to read the entirety of a directory for filenames or the entire contents of a .txt file. The problem I'm facing is with the implementation of Input_Xlsx. For interaction with .xlsx files I'm using a library called xlnt. The simple read() function is not enough for reading a .xlsx file as I need to provide the Input_Xlsx object with the following details:
- spreadsheet path
- worksheet to access
- range to read
- first cell to read
While it would work to just plop those variables into the definition of Input_Xlsx, I would not able to access it via a base class pointer so that I could, for instance, iterate over multiple input lists of various types:
[code]
InputSrc* test = new Input_Xlsx("test/spreadsheet.xlsx");
// the below two lines cause a compilation error as they're not defined in InputSrc
test->setRange("C:C");
test->cursor("C2");
test->read();
[/code]
... that took a while to write down.
My question now is if you know of any better way to structure my program? Did I overcomplicate things? What would be the best way to proceed? Should I just give up and just go back to GMod and play with ZCPU's?
Thank you all in advance![/QUOTE]
By asking myself the right question and with a bit of Google-fu I found that you can use static_cast to allow base class pointers to access functions of a derived class as seen below:
[code] InputSrc* test = new Input_Xlsx("test/spreadsheet.xlsx");
// no compiler errors! Unless you use the wrong functions
static_cast<Input_Xlsx*>(test)->setRange("C:C");
static_cast<Input_Xlsx*>(test)->cursor("C2");
test->read();
[/code]
Hope this proves useful to anyone who stumbles upon plights similar to mine.
Now, to resume the road to self-destruction...
Just keep the derived pointer and then explicitly cast up to base if you ever need to (which I can't see why you would). static_casting from base to derived is undefined behavior if you do it incorrectly, and no diagnostic is required so that means you'll get a segfault in the best case.
[editline]30th September 2017[/editline]
You're probably quite new to C++ but I suggest learning modern C++ from the get go (C++11 onwards), at least when it comes to memory management. Look into std::unique_ptr, it means you don't have to worry about new or delete. Might be a little tricky to understand right away but just want you to keep that in mind the further you go.
I need to do some testing for Controller support in Unity. Is it possible to force my Xbox 360 Controller to be Player two, three or four? I only have a single controller.
Assuming i have a tree like this
[img]http://carp.tk/$/NQbwsR.png[/img]
the correct order of iteration would be
[code]I, A, B, Test, J, E, K, G, C, F, D, H[/code]
and for this tree
[img]http://carp.tk/$/a8i6Dn.png[/img]
the correct order would be
[code]A, Test, B, C, D, E[/code]
How would i implement an algorithm to iterate it like this?
[QUOTE=cartman300;52740356]Assuming i have a tree like this
[img]http://carp.tk/$/NQbwsR.png[/img]
the correct order of iteration would be
[code]I, A, B, Test, J, E, K, G, C, F, D, H[/code]
and for this tree
[img]http://carp.tk/$/a8i6Dn.png[/img]
the correct order would be
[code]A, Test, B, C, D, E[/code]
How would i implement an algorithm to iterate it like this?[/QUOTE]
Looks like slightly modified Depth First Search starting on Test node.
Yup kind of. I solved it by finding the leaf nodes (I J E K F H) and then finding the path to the parent and skipping the nodes which were already visited.
[QUOTE=WTF Nuke;52732610]Just keep the derived pointer and then explicitly cast up to base if you ever need to (which I can't see why you would). static_casting from base to derived is undefined behavior if you do it incorrectly, and no diagnostic is required so that means you'll get a segfault in the best case.
[editline]30th September 2017[/editline]
You're probably quite new to C++ but I suggest learning modern C++ from the get go (C++11 onwards), at least when it comes to memory management. Look into std::unique_ptr, it means you don't have to worry about new or delete. Might be a little tricky to understand right away but just want you to keep that in mind the further you go.[/QUOTE]
I think I'm overcomplicating my solution, as I always do. My code is a big pile of mess currently and I'm thinking of just starting over from scratch again.
In the end I want to hold a list of InputSrc pointers to multiple derived classes (Input_Xlsx, Input_Dir, Input_Txt etc). Input_Dir and Input_Txt work fine as part of the list, but Input_Xlsx requires additional arguments to read the right information. I was thinking of getting the extension of the file and if it's .xlsx to do a static_cast<Input_Xlsx> on the base pointer to get the derived functions as well. If it isn't then we can just throw an exception.
You don't need explicit casts, just do this:
[cpp]Input_Xlsx* test = new Input_Xlsx("test/spreadsheet.xlsx");
test->setRange("C:C");
test->cursor("C2");
test->read();
std::vector<Input_Src> sources;
sources.emplace_back(test); // Works even if it's an Input_Xlsx[/cpp]
If you really need to cast Input_Src to Input_Xlsx do a dynamic_cast instead, because that will return nullptr instead of undefined behaviour.
Hello friends, for the past couple of days/weeks I have been attemping to write my own language in Lua (I chose Lua purely as a prototyping language so I dont have to battle with types and verbose syntax).
Currently I am trying to do expression parsing with correct precedence and associativity and so far its parsing, but not correctly.
An example expression `2 + 3 * 4 + (3 * 4) / 5` gets parsed as `((2)+((3)*((4)+(((3)*(4))/(5)))))` which obviously is wrong.
This is my first time trying to implement expression parsing and I'm quite near breaking point.
I have read [url]http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/[/url] and I have tried to implement a version of it without abstractions (mostly because of Lua but also because I'm lazy) and as you can see its not paying off.
Here is a link to the expression parsing: [url]https://bitbucket.org/GamerGambit/luavm/src/15c203beec69e04fb9f9c1ada6c52a7b75cbbbb4/parser.lua?at=default&fileviewer=file-view-default#parser.lua-275:532[/url], code is testable with `local p = require("parser") p:parse("2 + 3 * 4 + (3 * 4) / 5") printTable(p.tree)`
As you can see theres roughly 260 lines of code for it, which I understand is a lot and I'm not hopeful that anyone is willing to read through all of that. I dont really know how to create a more complete and short example since I dont know what the problem is or how to reproduce it. The commit linked is the second time I have written this parser and its giving me example the same results so I'm doing something wrong.
As opposed to asking/expecting anyone to read through it on their own accord, I'm willing to actually pay someone/s to read through it and help me out. Any help/suggestions directly related or not are more than welcome.
I've been overhauling my engine's asset system and thought I'd do some research on to what degree OpenGL could be multithreaded.
So I found that multithreaded rendering is pointless, but instead OpenGL can share resources between contexts and can use multiple contexts for content streaming.
I'm still in the research phase, but I just wanted to know if this is an appropriate usage of it:
Would it be wise to leverage this context resource sharing potential by creating a separate thread and having it be responsible for shipping data to the GPU (ie vertex and pixel uploading)?
Before I realized that it was technically possible, I already made a small system that create assets as much as possible on a separate thread and then submit them as workorders to the main thread with the main rendering context, and then slowly ship them to the GPU as to minimize slowdown of the rendering thread.
I guess what I'm trying to ask, does having multiple contexts share resources cause any performance loss on its own? Does uploading data to the GPU from a secondary thread while the primary thread is rendering cause any performance drop?
[editline]5th October 2017[/editline]
Also, can Pixel Buffer Object's be safely used with Bindless Textures?
IIRC, bindless textures are very strict in that they cannot be modified once the 64bit handle is given, so do I have to delay getting the handle until the PBO finished delivering the data, somehow?
Of course I plan on eventually trying this all out.
In any case, I'm so excited that there are even more ways I can make my system better.
Is there a way in Visual studio to have all the source files for a new project get created within a specific folder within the project folder, like an "include" folder?
Like:
[code]
<Project Folder>
<Binaries>
<include>
[/code]
I'm trying my hand at library creation in VS2015
[QUOTE=Karmah;52757830]Is there a way in Visual studio to have all the source files for a new project get created within a specific folder within the project folder, like an "include" folder?
Like:
[code]
<Project Folder>
<Binaries>
<include>
[/code]
I'm trying my hand at library creation in VS2015[/QUOTE]
I just tell it where to put every file when I create the file usually? It remembers the location during a session which has been good enough for me. If you're using like the class wizard or whatever I don't remember whether that also has the location dialog though.
It doesn't ask for me, though I can just manually create the files and manually add them to the project, it's just slower.
Better then nothing :pudge:
How do you guys keep yourself interested and motivated programming? For a few years now, I've been programming a lot but I can't seem to stick with a single language/framework. I'm constantly considering switching to something else, and I cant pick a language to learn and master. I'm out of Ideas.
[QUOTE=BOT Ferris;52759102]How do you guys keep yourself interested and motivated programming? For a few years now, I've been programming a lot but I can't seem to stick with a single language/framework. I'm constantly considering switching to something else, and I cant pick a language to learn and master. I'm out of Ideas.[/QUOTE]
I've dabbled in various languages over the past few years, but my bread and butter is C#. It's C# because that's what Unity3d uses for game development, and I intend to create a game. I don't even like Unity3d all that much, but thankfully C# is adaptable to other engines. If someday I decide C# isn't good enough, I'll begin dabbling in C++. Maybe I'll just use C++ for performance-heavy libraries and import them into my C# project.
There's no issue with using multiple languages, either. My game consists of HTML, CSS, Javascript, C#, and Lua.
Just ask yourself why you're interested in programming, and what do you want to create?
[QUOTE=Karmah;52759038]It doesn't ask for me, though I can just manually create the files and manually add them to the project, it's just slower.
Better then nothing :pudge:[/QUOTE]
When using the new file dialog it should allow you to specify the path really.
What do you guys use to record your screens and post the videos?
I use sharex. It's freeware and developed by a guy here on FP
quick question, i've got a bunch of games i've found on dropbox and box.net that i've uploaded over the years. they were games i made in game maker years ago and i no longer have the source to any of them.
i'm not actually after the source though, just all the sprites and background tilesets and shit i drew for them. normally with game maker games i could just use a tool to decompile the exe, but for a lot of the ones i want to get resources from i passed the exes through a tool that makes it so a decompiler doesn't work.
is there any way to get the image files from an exe?
[QUOTE=Pat.Lithium;52760927]quick question, i've got a bunch of games i've found on dropbox and box.net that i've uploaded over the years. they were games i made in game maker years ago and i no longer have the source to any of them.
i'm not actually after the source though, just all the sprites and background tilesets and shit i drew for them. normally with game maker games i could just use a tool to decompile the exe, but for a lot of the ones i want to get resources from i passed the exes through a tool that makes it so a decompiler doesn't work.
is there any way to get the image files from an exe?[/QUOTE]
I imagine you could probably get bitmap data through something like ida right? Cause in order to be rendered it has to be bitmap data?
Sorry, you need to Log In to post a reply to this thread.